How to activate process instance on receiving a REST call?

I have a scenario where after just starting the process instance I need to set the variable to the process instance and suspend it. Then the process instance needs an external REST call with process instance id to activate the instance again. How can I achieve this?

Hey @aashi,

I am not quite following. What exactly do you need? Do you need the id of the process instance or you need the REST API for activating the instance?

Cheers,
Filip

Hey @filiphr,

startEvent --> setProcessVariableAndSuspendProcessInstance --> On Trigger of my api with processInstanceId I need to activate the process instance again --> someOtherTask --> endEvent

I have created this highlighted task as a userTask which on trigger of rest api, would activate this process instance again.

I’m using below line of code to activate the process instance again,
processEngine.getRuntimeService().activateProcessInstanceById(actionId);

After this I’m expecting that the process instance will resume and executes all the other tasks, which is not happening.

I am not sure what you are trying to achieve. However, a process can go into a suspended state when it is in a wait state. From what you are explaining it feels like you want to stop the process in the middle of the execution. This is not possible.

Can you please tell us the problem you are trying to do, not the technical details. I think that you need something like a signal or message received events.

Cheers,
Filip

Hello @filiphr,

I’m a newbie in Flowable world so i’ll try to explain to my level best. Pardon me for that !

When I’ll trigger 1st REST call of my app I need to start a flowable process instance, set some variable to it and then process instance wait until the 2nd REST call is triggered. As soon as the 2nd call is triggered, process instance should leave the waiting state and continue with the rest of the tasks.

You could add a user task after the start event and create custom endpoints to start the process and complete the user task:

@RestController
@RequestMapping("/rest-driven-process")
public class ProcessController {

    private final RuntimeService runtimeService;
    private final TaskService taskService;


    public ProcessController(RuntimeService runtimeService, TaskService taskService) {
        this.runtimeService = runtimeService;
        this.taskService = taskService;
    }

    @GetMapping("/start")
    public String startProcess() {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("restDrivenProcess");

        return processInstance.getProcessInstanceId();
    }

    @GetMapping("/continue/{processInstanceId}")
    public String continueProcess(@PathVariable("processInstanceId") String processInstanceId) {
        List<Task> tasks = taskService.createTaskQuery().taskDefinitionKey("secondRequest").processInstanceId(processInstanceId).list();

        tasks.stream().forEach(task -> taskService.complete(task.getId()));

        return tasks.size() + "complete";
    }

}

Example Code: https://github.com/unamanic/flowable-custom-rest

I hope I understand your requirement, but I think you can use the standard rest api with intermediate message event.

  1. Start your process
  2. The process stops and wait for the message event.
  3. You call the rest api to send a new message to your process
  4. The process continues.