Hi,
I am new with Camunda BPM. I Can start my Process and change state of my process instance.
I have to add some variables when another application call a custom Camunda custom endpoint with business key.
How to add a variable at a running instance ? I just have a business key to retrieve process instance.
Here is my codein my custom endpoint
ProcessInstance processInstance = processEngine.getRuntimeService() .createProcessInstanceQuery()
.variableValueEquals("businessKey", 657).singleResult();
How to add variable(key and value) in this process instance ?
Thanks
Tank you for your answer . How to get the execution from processInstance.
Here is the code to use but i don’t undestand i to get execution :
runtimeService.setVariableLocal(execution.getId(), "order", serializedValue);
@pracedeb how do you setup your camunda application? Spring boot or tomcat distribution?
It’s a spring boot application
@pracede refer this code below:
@Service
public class ProcessEngineService {
@Autowired
private RuntimeService runtimeService;
public void setProcessVariablesToInstance(String processInstanceBusinessKey) {
Execution execution = runtimeService.createExecutionQuery().processInstanceBusinessKey(processInstanceBusinessKey)
.singleResult();
CustomerDTO customerDTO = CustomerDTO.builder().id("C3462").name("Willy Brandt").address("Germany").build();
ObjectValue customerDataValue = Variables.objectValue(customerDTO)
.serializationDataFormat(Variables.SerializationDataFormats.JAVA).create();
Map<String, Object> variableMap = new HashMap<>();
variableMap.put("customerDataValue", customerDataValue);
variableMap.put("category", "politics");
variableMap.put("activeStatus", true);
//to set multiple variables to process instance
runtimeService.setVariables(execution.getId(), variableMap);
StringValue typedStringValue = Variables.stringValue("a string value");
//to set one variable to process instance
runtimeService.setVariable(execution.getId(), "stringVariable", typedStringValue);
}
}