Save state of checkboxes

Hi there,

I’m using embedded task forms and I have some checkboxes for Boolean process variables like this:

<input type="checkbox" cam-variable-type="Boolean"
		cam-variable-name="first_day_mailing_lists"
		name="first_day_mailing_lists"> FooBar

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).

Cheers,
Frank

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.

1 Like

Thank you very much. Could you please explain your approach a little bit further?

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.

Thank you guys.

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());
    
      	}
    
      }
      }
    
  • In the task form I use the store event

      camForm.on('store', function(evt) { ... ; evt.storePrevented = true; }
    

    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.

Cheers,
Frank

1 Like

Thanks for sharing your solution!