Process variables scope

How can we se the local task variable in camunda.
We have the option to set the variables in process instance scope, but no option to create the variables in
task scope or child scope only…

Can you let me know which method are you using to set the variables and why you need to use task variables?

Hi Niall,

As we read about parent scope and child scope in Camunda Docs.
What I want to know is that when we set the process variables, it is accessible to full instance or parent scope.
I want to set the variables as local or child scope or Task variable only.
There is no clarity about how we can set the variables in local scope from Camunda UI.

In short I want to know the different ways of setting variables in Camunda, some at parent scope and some at child scope.

Any help would be appreciated.

Thanks.

1 Like

Hi @SudhirBisht,

I think we missed the most basic and simple setter in the docs at a prominent place.

If you are outside, you can write runtimeService.setVariableLocal(executionId, variableName, variableValue);

Or inside a delegate or listener write execution.setVariableLocal(variableName, variableValue);

Hope this helps,
Ingo

2 Likes

Ok…that I read about, is there any way to set these variable local from Camunda UI.
And the call hierarchy for setting the local variable from rest API.

The REST-API is here: https://docs.camunda.org/manual/7.7/reference/rest/execution/local-variables/.

But Cockpit isn’t able to set new local variables.

To set local variables in user forms, the most easy way is to define them in a task-listener creating the task. Then you can reference the variables with cam-variable-name in the form.

Have a look at this post for further details: Variables in parallel process

Hope this helps,
Ingo

1 Like

Yes it helps, Just few more things I want to understand.

  1. Does the local variable automatically delete from the Database as well when we exit the task in the flow,
    or we have to delete the local variable using Rest call.

  2. when we are talking about the executionId, does that mean the task Id in which we want to set the local variable…?

  1. Yes. If the scope is left, all variables bound to this scope will be deleted from the runtime tables. But they remain in the history tables, if the history level is sufficent.

Executions are different from task and have different ids. Have look at these docs (https://docs.camunda.org/manual/7.7/user-guide/process-engine/variables/#variable-scopes-and-variable-visibility) again to get an idea about their relationship.

Cheers, Ingo