Retrieving results from process instance

I have the following running service. Its an extension of the dish tutorial. combining bpmn with dmn.

@Component
@Slf4j
public class ProcessService {

    @Autowired
    private RuntimeService runtimeService;

    public String getDish(){
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("DishGenerator");
        return unsureAboutThisBit;
        // how do I get the dish response that was set on the final JavaDelegate task do I save it to a variable?
    }
}

My final task int he BPMN looks like this

@Component
public class DishReviewDelegate implements JavaDelegate {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    public void execute(DelegateExecution execution) throws Exception {

        logger.info("reviewing output of dish decision");

        logger.info("available keys:{}", execution.getVariables().keySet());
        String dish = (String) execution.getVariable("dish");
        String result = (String) execution.getVariable("result");
        logger.info("dish is {} ", dish);
    }
}

So my question is this… How do I get the dish value from the ProcessService class - the one that triggers the process?

Hi @Rob_Davidson,

Assuming there are no wait states in the process, you can use the documented here to access the variables of the completed process instance.

Cheers,
Thorben

@thorben which rest API can be used?

Hi @abc-xyz,

Have a look at below example of starting a process instance with variables in return

https://docs.camunda.org/manual/latest/reference/rest/process-definition/post-start-process-instance/#starting-a-process-instance-with-variables-in-return