Reputation: 18415
Problem
I have several Activiti task types, the base types are ServiceTask
and UserTask
.
Some ServiceTask
types are Java implementations, each of them different. Then there are others.
I'd like to distinguish them in my code.
Question
Is it possible to store some custom attributes / properties in the tasks and if so, how?
Example:
A ServiceTask
that implements simple Logging functionality should have a property "TYPE" with the value "LOGGING" which I can then query later.
I tried using FieldExtension
, but when I run the workflow, Activiti throws the error:
org.activiti.engine.ActivitiIllegalArgumentException: Field definition uses unexisting field 'TYPE'
Same happens for CustomProperty
.
Of course I could solve that by declaring the field in the Java class, but I need a solution that works also for non Java service tasks and for user tasks. Or better yet if possible for all flow elements.
Thank you very much!
Upvotes: 3
Views: 4291
Reputation: 3468
You can define fields in XML/Designer:
<serviceTask id="javaService"
name="Java service invocation"
activiti:class="org.activiti.examples.bpmn.servicetask.ToUppercase">
<extensionElements>
<activiti:field name="text" stringValue="Hello World" />
</extensionElements>
</serviceTask>
If you want to access the field in Java code you can do it like that:
public class ToUppercase implements JavaDelegate {
Expression text;
public void execute(DelegateExecution execution) throws Exception {
String value = (String) text.getValue(execution);
value = value.toUpperCase();
execution.setVariable("upperedText", value);
}
}
If you want to access variables in UserTask you have to implement TaskListener instead of JavaDelegate.
Upvotes: 4