Edit variable in Externally Terminated process instance

Would like to know if it is possible to edit a task variable after the process instance is in EXTERNALLY_TERMINATED state.

We need to update the variables of a workflow which was stopped externally and then restart the workflow.

While trying to edit a variable in the above scenario, we get the below error:

{“type”:“RestException”,“message”:“Cannot modify variables for execution 4518c407-2f79-11e9-a048-0242ac120009: execution 4518c407-2f79-11e9-a048-0242ac120009 doesn’t exist: execution is null”,“statusCode”:500}

Kindly confirm it is possible to edit the variables for a failed/externally_terminated processinstance.

Thanks in advance.

Variables can be updated only for active process instances. Updating variables in Completed process instances/Externally terminated is not possible.

Before terminating the process instance you can update the variable.

Thanks for the confirmation.

Updating a variable in a running instance would update the variable history in the original instance itself. However, in our requirement, we need to update a variable only on the new instance created by restart. Please let us know if it is feasible.

What you are trying to update?

I think, only feasible way to updating a variable in a running instance is by determining the deleteReason=EXTERNALLY_TERMINATED flag will be stored in ACT_HI_TASKINST table if the process instance was terminated. This you can query via Historic Task rest api.

For example, you have initiated a process instance with variable productPrice = 10USD and in subsequent activities the value got updated as productPrice = 20USD, after that due to some reasons if the process got terminated and you are trying to restart a process instance with inital value as productPrice = 10USD, then you can try the below approach.

runtimeService.restartProcessInstances(processDefinition.getId())
  .startBeforeActivity("activity")
  .processInstanceIds(processInstanceIds)
  .initialSetOfVariables()
  .execute();

This will restart process instance by resetting the values used during start of a process instance.

Initial Variables allows you to set the initial set of variables. By default is is the last set of variables used.

For Rest API refer,
https://docs.camunda.org/manual/7.8/reference/rest/process-definition/post-restart-process-instance-sync/