cancel
Showing results for 
Search instead for 
Did you mean: 

New variable scope is created for service task with boundary error event

garhing_
Champ in-the-making
Champ in-the-making
In my process diagram, I have a multi-instance sub-process. Inside the sub-process the start event transitions to a service task which has a boundary error event on it.

The service task tries to get the loop counter from the local scope using execution.getVariableLocal("num") but it cannot. The loop counter can be retrieved using execution.getVariable("num") though. After some debugging I've found that when the service task has the boundary error event on it, an additional, empty variable scope is created as a child of the scope which contains the "num" variable. If the service task has no boundary error event, Activiti will no create the extra child scope.

It seems to come down to the ActivityImpl object representing the service task having the "isScope" flag set to true when the boundary error event is on the service task.

Is this desired behaviour? Should a new scope be created when entering a service task with a boundary error event on it?
3 REPLIES 3

jbarrez
Star Contributor
Star Contributor
Yes, a new scope is created when an activity has a boundary event (and multiple other cases too).

garhing_
Champ in-the-making
Champ in-the-making
So should service tasks always use the getVariable(String) method so that they don't need to know which level of scope they're using? And does this mean that service tasks that use getVariableLocal(String) must be modified if the process diagram is changed to put the service task in a new scope?

Is there much documentation on scopes in Activiti? If not, could you provide me with an overview on how scopes work in Activiti?

trademak
Star Contributor
Star Contributor
Yes getVariable would be the best approach. Multi-instance activities, user tasks and process level scopes are currently used in Activiti.

Best regards,