How to get the Process Instance ID with Java?

Hi, I would like to know how to get the Process Instance ID that I see at the Camunda’s Cookpit (List of Process Instances):

processId

And it’s the same that I see at the message response:

processIdJson

Yes, I tried the “execution.getProcessInstanceId();” (even the execution.getId()) and it’s not the same

Thank you very much!

Hi,

What is the context? Where do you try to fetch the process instance id - delegation code or somewhere else? What is your goal?

Hi @Yana thanks for your reply.

I have a process that starts by a message, if I send a message REST I succeeded to start the process and, like you can see at the image that I attached, the reponse have the information related the Process Instance started. If I send another message another instance starts, so far so good.

But, what do I have to do if I need to continue the firts instance? (my process waits for another message in order to continue), I tested and I added the “process instance id” to my message because I think that’s the way to correlate the message to the correct instance, and that works, because the instance that I need to continue it continues, but I did that with copy and paste the id string (by hand).

In my Java application, when I start the process I save an entity to the database, and I try to save it with its process instance id (execution.getProcessInstanceId()), when I receive the second message to continue my idea it’s to get the processInstanceId to recover that from the database and update the correspondant entity at the database.

Maybe the real question is if the way that I try to correlate the messages to the correct instance is this the best way?

Thank you very much!