Process Instance Id is not returned immediately after the REST call to start a process

I have designed a bpmn file to extract some orders with a webservice task.( see the attachement).
<img src="/uploads/default/original/2X/7/70d23ac2955a8e41b8146c98711efaaaaecc32f0.png" width=“586” height="92

I have an issue in saving the processInstanceId in DB. Before starting this process I create a record in DB with processname and updating the same record with the processInstanceId once I receive the response (I use the rest api POST /process-definition/key/{key}/start to trigger the process) from the REST call. However I am getting the response only after the whole process is completed. So what happens is , there are other DB calls within the service task that looks up the same record with processInstanceId fails. Because the processInstanceId might not have updated by that time.

However if I add one usertask just after the start event , it immediately returns a processInstanceId.

Is there any other way where I can get the processInstanceId immediately after the rest call.

Attaching the diagram

The issue is that your process has no “wait states”. When running a process the engine will run in memory until it reaches a state in which it must commit to the database (User Task, Receive Task… etc).

Since there is no wait state the process stats and runs the whole process in memory and only commits when the process reaches the end event.

Luckily enough it’s pretty easy to create custom wait states by selecting Async Before or Async After on an element. This will for the process to commit it’s state before or after a specific symbol.

1 Like

Ok. Thanks for the information. It worked :slight_smile: