cancel
Showing results for 
Search instead for 
Did you mean: 

confused about local and global variable scope

sarkar92
Champ in-the-making
Champ in-the-making
with reference of this following userguide link
http://activiti.org/userguide/index.html#N14509
and
http://forums.activiti.org/content/scopes-and-variables-activiti

I am quite confused about variable scope…

I am trying to get all variable from a task
In the sub process scripttask i defined two local variable like
   
   execution.setVariableLocal("TestLocalVariabl1", "Test1");
   execution.setVariableLocal("TestLocalVariable2", "Test2");


while try to get all local variables from task its return nothing…
http://#######:6080/activiti-rest/service/runtime/tasks/223837/variables?scope=local

but when try get all global variables from task those local variables are return as response body 


{
    "name": "TestLocalVariabl1",
    "type": "string",
    "value": "Test1",
    "scope": "global"
  },
{
    "name": "TestLocalVariable2",
    "type": "string",
    "value": "Test2",
    "scope": "global"
  }




thanks
1 REPLY 1

frederikherema1
Star Contributor
Star Contributor
You're setting local variables on the execution-context, not on the task. So if you would ask for the local execution-variables of that execution, you would get them back. In your case, you have execution-local variables set which are threated as "global" variables for the task, since they are NOT set on the task local but on it's parent (or ancestor).

Use this to set real task-local variables (or use the REST-API to set local task variables, see userguide):


taskService.setVariableLocal("myVar", "localValue");