Now I would expect that when user A checks that checkbox and saves the task (via “Save” button), user B will see the checked state of the checkbox when opening the task in his browser afterwards.
However, this does not work. For user B, the checkbox still appears to be unchecked.
Is that a feature or a bug?
How can I achieve the desired behaviour (–> user B sees the changes user A made to the variables).
This is expected behavior - the Save button just stores the data in the browser cache.
You’ll need to change you’re model to get the behavior you’re looking for. A loop with a dynamic user would do the trick.
If the task is completed with the variables set and there is some kind of loop which reactivates the same task - it would be populated automatically with those variables.
I was able to figure out a way to solve this issue without having to modify the process flow.
Here is how I did it:
I created a method in the backend which is available via REST call and allows to modify a process instance variable (input parameter is a processInstanceId and a list of tuples (variableName, variableType, variableValue))
@POST
@Path("update-process-variables")
@Consumes("application/json")
public void updateProcessVariables(List<ProcessVariableDto> processVariables) {
for (final ProcessVariableDto dto : processVariables) {
LOG.fine("Updating process instance " + dto.getProcessInstanceId() + ". Set variable "
+ dto.getVariableName() + " of type " + dto.getVariableType() + " to '"
+ dto.getVariableValue()
+ "'...");
if (dto.getVariableType().equalsIgnoreCase("Boolean")) {
final boolean val = Boolean.valueOf(dto.getVariableValue());
getProcessEngine().getRuntimeService().setVariable(dto.getProcessInstanceId(), dto.getVariableName(),
val);
} else {
getProcessEngine().getRuntimeService().setVariable(dto.getProcessInstanceId(), dto.getVariableName(),
dto.getVariableValue());
}
}
}
to call the method from above via JavaScript. Note that it is important to set evt.storePrevented = true; otherwise you will have trouble with the form data being saved to localStore.