Programatically creating service task with local variable


I could not find how to assign variable local to a Servicetask before the execution. I am programatically creating BPMN model from start. If there is a way. Is taskListener part of process definition? I would appreciate some snippets.

I saw setDataInputAssociations/setDataOutputAssociations methods in ServiceTask. Could not find more info about it.
What goes for the fields “transformation” and “assignments” in DataAssociation object? Does it associates data among variables available to RuntimeService (or Execution, do they access same sets of variables?)?

In other words, am I correct in assuming that I would be able to associate different task i/o variables and process instance -variables using this method?
say, I have a process instance variable:
String input1=“someValue”;
When task1 gets to execution, I would like to assign local var
task1.input1 = input1

additionally, say I got
String task1.output1=“someTaskVal”;
When task2 gets to execution, I would like to assign local

Thanks in advance.


You could add a start execution listener to the service task and set the local execution variable in there.

Best regards,


I think you can use task script listener to set and store values.
There is example in documentation how to use groovy script and return value to execution context.