cancel
Showing results for 
Search instead for 
Did you mean: 

Scopes and Variables in Activiti?

danielbehrwind
Champ in-the-making
Champ in-the-making
Hi,

I'm new to Activiti and trying to learn more about scopes and variables. I've been browsing the user guide, API doc an forum, found some hints but haven't been able to grasp the overall concept. Here's what I learn so far:

It is possible to define variabels in process and in task scope. Both, the RuntimeService and TaskService provide corresponding methods. There are methods called get/setVariable and get/setVariabelLocal. What does "local" mean in this case?

There is an Interface VariableScope and several classes whose names start with "VariableScope". Is there a way to defnie custom scopes? How would one access them?

Would be great if anyone could outline the concept of scopes in Activiti or point me to some documentation.

Thanks Smiley Happy
Daniel
6 REPLIES 6

trademak
Star Contributor
Star Contributor
Hi,

If you invoke the setVariable method with a process instance ID then you set a global variable for the whole process instance.
setVariableLocal can be used for example in a Java service task in a sub process to set a local variable that can be used by other tasks in the same sub process.
Scopes are things like the process instance scope, a sub process scope or a single task scope.

Best regards,

mstein
Champ in-the-making
Champ in-the-making
I know this is probably a dead thread, but maybe we can bring it back to life.

I was hoping for some additional clarification here. My scenario is I have a multi-instance subprocess, that contains a multi instance user task.

Subprocess
collection: myObjects
variable; myObject

Service Task
//get information from the myObject POJO create a local variable 'users'

UserTask
collection: users
variable: user
assignee: ${user}


this is resulting in an unknown property for user. Is this a scope issue?

Thanks inadvance for your help.

mederly
Champ in-the-making
Champ in-the-making
Hello,

I struggled with a similar problem - multi-instance activiti within another multi-instance activiti just did not work. It was not initialized correctly.

The problem seems to be in this:

class MultiInstanceActivityBehavior, method execute(ActivityExecution execution);

originally it looks like this:

  if (getLoopVariable(execution, LOOP_COUNTER) == null) {
      try {
        createInstances(execution);
      } catch (BpmnError error) {
        ErrorPropagation.propagateError(error, execution);
      }
    }

However, the inner multi-instance cycle "sees" here the loopCounter from the parent one, so it does not properly initialize its own instance. After replacing getLoopVariable call with "getLoopVariableLocal", looking e.g. like this:

    protected Integer getLoopVariableLocal(ActivityExecution execution, String variableName) {
        return (Integer) execution.getVariableLocal(variableName);
    }

it seems to work.

I have to test it more thoroughly, however.

PS: there seem to be more faults in code dealing with multi-instance things related to variable scopes, like several of "setLoopVariable" calls, which do not distinguish between scopes - they place all the information in the local scope, although some data should go to local scope, and other to the parent one. It would be worth fixing.

jbarrez
Star Contributor
Star Contributor
Yes, you are probably correct about the scoping.

Could you create a jira so I can follow up and fix it?

mederly
Champ in-the-making
Champ in-the-making
Joram,

certainly. Here it is: https://jira.codehaus.org/browse/ACT-1426.

Pavol

jbarrez
Star Contributor
Star Contributor
Thanks, I'll look into it.