cancel
Showing results for 
Search instead for 
Did you mean: 

Task Scoped variables

bkwf2
Champ in-the-making
Champ in-the-making
Hi,

I have some questions regarding task scoped variables.

I have a process with 4 tasks like below:

      [Task 1] —> [Task 2] —> [Task 3] —> [Task 4]

When user completes Task 1 certain business data is generated and I want to set this data in "Task" scope so that when control passes to the task 2 I can access the data.

In order to complete the task 1 I call the below code:


TaskService taskService = getTaskService();
taskService.complete("task_1_Id", variables);
   
But the variables are set in the "PROCESS" scope since when I check table "ACT_RU_VARIABLE" table I see the "TASK_ID_" column as NULL. This is correct since the task ends with call to "complete". And yes when I reach Task 2, I can access these variables using "taskService.getVariables(taskId)", but this method will access the variables in "PROCESS" scope also.

I tried using the below code to store the variables at a "local" scope:



TaskService taskService = getTaskService();
taskService.setVariableLocal(taskId, varName, value);


But this also did not help.

To cut to the chase I am trying to limit some variables to "TASK" scope which would not be visible at the "PROCESS" level. Is this possible..?
Or are all variables always stored in "Process scope"..?
Or am I not understanding the scopes correctly..? I have read the Activiti docs from top to bottom, but could not find a clear explanation of "scopes". I know one thing that there is a local scope and variables are first searched at local scope and then in the parent scope. :roll:

thnx for any advice.

Bhushan
4 REPLIES 4

trademak
Star Contributor
Star Contributor
Hi,

You do have a local task scope in Activiti, but when you want to use variables in task 2 that you set in task 1 you'll only have the process scope available.
You can still add a sub process and use the scope of the sub process to set variables.

Best regards,

ssun
Champ on-the-rise
Champ on-the-rise
I am facing the same issue. I would like to see that from the UI, we can pass down task level variables just like we do for process to sub process.

rhiremat
Champ in-the-making
Champ in-the-making
tasks.getTaskLocalVariables() - what is different for this call than the  processInstance.getProcessVariables() call?

-Raj

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

current implementation is the same

  public Map<String, Object> getTaskLocalVariables() {
    Map<String, Object> variables = new HashMap<String, Object>();
    if (queryVariables != null) {
      for (VariableInstanceEntity variableInstance: queryVariables) {
        if (variableInstance.getId() != null && variableInstance.getTaskId() != null) {
          variables.put(variableInstance.getName(), variableInstance.getValue());
        }
      }
    }
    return variables;
  }
  public Map<String, Object> getProcessVariables() {
    Map<String, Object> variables = new HashMap<String, Object>();
    if (queryVariables != null) {
      for (VariableInstanceEntity variableInstance: queryVariables) {
        if (variableInstance.getId() != null && variableInstance.getTaskId() == null) {
          variables.put(variableInstance.getName(), variableInstance.getValue());
        }
      }
    }
    return variables;
  }

Regards
Martin