How to retrieve completed workflow response (A variable set into DelegateExecution)?

I’m able to start the workflow using process id with input variables required from a Spring Boot REST api controller method(Line 1). This flow has condtional checks and will be redirected to Service Task based on the conditional expression. And the end of the flow I need to retrive the variable (which I’m setting into DelegateExecution of the Service Task) from where I’m starting the flow (REST api controller method). But I don’t have an option to access the variable using processInstance. Can someone please help me here?

With processInstance I only be able to get the processInstance id (Line 2).

// Line 1
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(“fetchStores”, Variables
.putValue(“countryCode”, params.get(“countryCode”))
.putValue(“storeNumber”, params.get(“storeNumber”)));

// Line2
logger.info(“started instance: {}, {}, {}”, processInstance.getRootProcessInstanceId(), processInstance.getProcessDefinitionId(), processInstance.getProcessInstanceId());

@Siddhaiyan_Krishnapp you can use the History service for querying variables for completed process instances like below.

List<HistoricVariableInstance> historicVariableInstances = historyService.createHistoricVariableInstanceQuery().activityInstanceIdIn(instanceId).list();

if (CollectionUtils.isNotEmpty(historicVariableInstances)) {
    Map<String, Object> historicVariableInstancesMap = historicVariableInstances.stream()
        .map(HistoricVariableInstanceDto::fromHistoricVariableInstance)
        .collect(Collectors.toMap(HistoricVariableInstanceDto::getName, HistoricVariableInstanceDto::getValue));
    return historicVariableInstancesList;
}
1 Like

Thank you so much Aravind for your response and it worked. I came to know that using this HistoryService will cause the performance impact. Is that true? I’m new to Camunda workflow and earlier we planned to integrate Camunda workflow with our Spring Boot application for business logic. Due to these kinda issues and lack of knowledge on Camunda Spring Boot integration we are reverting the changes :frowning:
Could you please suggest some idea whether we can integrate Camunda workflow in our Spring boot application

Yes, you can use it. Clearing up old historic instances improves query time and storage. You can refer to Camunda History TTL flag settings.