'How to set processwide variables in Activiti?

I am trying to set process-wide variables, which are shown not only in the next task but also in workflow details view.

I tried: (ServiceTask)

execution.setVariable("san_value", "1000");

or: (TaskListener)

String myprocessinstanceid = delegateTask.getProcessInstanceId();
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RuntimeService myruntimeservice = processEngine.getRuntimeService();
myruntimeservice.setVariable(myprocessinstanceid, "san_value", delegateTask.getVariable("san_value"));

But with this code I am only able to pass variable from one task to another. But when I enter "Workflow Details" view, all variables are empty!

How can I set them?

PS. Do I really have to set every variable in every single task? Shouldn't it be automatic?



Solution 1:[1]

RuntimeService.setVariable takes execution ID as the first variable, not process instance ID.

So pass in the delegateTask.getExecutionId() instead.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steven