Hello everybody,
Is there a way to retrieve the variable which was set at a process after the process complete?
Thank you!
Hello everybody,
Is there a way to retrieve the variable which was set at a process after the process complete?
Thank you!
@Yury, Do you want to retrieve process variables for the completed processes?
@aravindhrs yes, I do.
The situation looks something like this
@PostMapping(value = "/question")
public ResponseEntity<ResponseToUi> sendQuestion(@RequestBody questionDto questionDto) {
VariableMap variableMap = Variables
.putValue("question", questionDto.getQuestion());
runtimeService.startProcessInstanceByKey("questionProcess", variableMap);
//during the execution process, I set up a variable which shows me which response I should send to the client
//retrieve value
if(*some condition with retrieved value*) {
throw new CustomException();
}
return new ResponseEntity<>(new ResponseToUi(SUCCESS, EMAIL_IS_SENT), HttpStatus.OK);
}
@Yury, I hope this might help you. By using DefaultProcessEngine history service can be accesed like:
HistoryService historyService = BpmPlatform.getDefaultProcessEngine().getHistoryService();
HistoricProcessInstance historicProcessInstance = historyService
.createHistoricProcessInstanceQuery().processDefinitionKey("processDefinitionKey")
.processInstanceBusinessKey("processInstanceBusinessKey").finished().singleResult();
List<HistoricVariableInstance> historicVariableInstances =
historyService.createHistoricVariableInstanceQuery()
.processDefinitionKey(historicProcessInstance.getProcessDefinitionKey())
.processInstanceId(historicProcessInstance.getId()).list();
String variableName = historicVariableInstances.get(0).getName();
Object variableValue = historicVariableInstances.get(0).getValue();
If you have named process engine, then history service can be accessed like:
BpmPlatform.getProcessEngineService().getProcessEngine("name").getHistoryService();
@aravindhrs Thank you!
I will try this solution
@Yury, In Spring environment, you can directly access the history service by autowiring.
@Autowired
private HistoryService historyService;
Then,
HistoricProcessInstance historicProcessInstance = historyService
.createHistoricProcessInstanceQuery().processDefinitionKey("processDefinitionKey")
.processInstanceBusinessKey("processInstanceBusinessKey").finished().singleResult();
List<HistoricVariableInstance> historicVariableInstances =
historyService.createHistoricVariableInstanceQuery()
.processDefinitionKey(historicProcessInstance.getProcessDefinitionKey())
.processInstanceId(historicProcessInstance.getId()).list();