Process Instance ID runtime viarable

cancel
Showing results for 
Search instead for 
Did you mean: 
jaco1
Active Member II

Process Instance ID runtime viarable

Jump to solution

Hi. Is there a variable I can use that holds the process instance id that I can pass during runtime to a rest call in the payload ?

Like this

{
 "itemkey": "${id}"
}

1 Solution

Accepted Solutions
sarveshmvm
Active Member II

Re: Process Instance ID runtime viarable

Jump to solution

Hi Jaco,

That should work. If this approach does not work, you can have a global variable at the process level and update them at every step and you can access directly activiti_ru_variable . It also depends on if your process is synchronous/asynchronous and make sure the Rest call gets the right process id before it moves to the next step. 

In one of my use cases I use global variable to maintain the status of every task .That should definitely work .

View solution in original post

11 Replies
sarveshmvm
Active Member II

Re: Process Instance ID runtime viarable

Jump to solution

execution.getProcessInstanceId();

This will always gives you the current process instance ID. If you need to access the instance of the process(Root Instance id) , you can try the below

execution.getParentId()

jaco1
Active Member II

Re: Process Instance ID runtime viarable

Jump to solution

Hi, Sathya G. Thanks for the reply. The problem I have is that I start a BPM process from an Oracle Apex Page.

When you start a process it will execute all the way until it gets to a Human Task and then it will return to the calling Apex Page.

As part of the process, there are REST calls back to Oracle Procedures that update worklist items before it gets to the first Human Task. Those procedures need values that live inside process instance variables. So for that Oracle procedure to get to the process variables I need the Process ID. I will only know what the process ID is once the call returns to my calling Apex Page. 

But if I can pass the Process id to the Oracle Procedure in the Rest call it will know what process to query on the Activiti side.

What I have done now is to place a Human task at the start with a timeout of 1 second. So when the Apex form creates the process it returns to the Form very fast and gives the Process Instance Id to the Form. The form then updates the request table with the Process ID. After the second when the process continues if will call the Oracle procedure than by this time now has the Process ID in the table and then all works.

Is there a default variable that I can use to pass the Process Instance ID to the Oracle Procedure via the payload?

Or can I use script code in that payload area to get the Process Instance ID ? There where I pass the CLAIM_NUMBER, I want to send the Process Instance ID also.

jaco1
Active Member II

Re: Process Instance ID runtime viarable

Jump to solution

can I do it like this ?

{

"itemkey": "${CLAIM_NUMBER}" ,

"processid": "${execution.getProcessInstanceId()}"

}

sarveshmvm
Active Member II

Re: Process Instance ID runtime viarable

Jump to solution

Hi Jaco,

That should work. If this approach does not work, you can have a global variable at the process level and update them at every step and you can access directly activiti_ru_variable . It also depends on if your process is synchronous/asynchronous and make sure the Rest call gets the right process id before it moves to the next step. 

In one of my use cases I use global variable to maintain the status of every task .That should definitely work .

jaco1
Active Member II

Re: Process Instance ID runtime viarable

Jump to solution

Hi. OK so this works if I keep the user task with the time out. I get this error if I do it all in one go.

Exception due to Activiti Object Not Found org.activiti.engine.ActivitiObjectNotFoundException: Could not find a process instance with id '30005'.

So it seems the process is synchronous as I can not access it from outside via the rest calls back to the process from the Oracle Procedures. It first needs to commit and return before I can access it. How do I make the process so it is asynchronous so I can call myself from a external oracle procedures during the start-up of the process ?

jaco1
Active Member II

Re: Process Instance ID runtime viarable

Jump to solution

Thanks soooo much. I got it working now. I had to mark all the tasks as asynchronous and now it returns like when I do it with the timer. I am new to Activity. Been using Oracle Workflow for 20 years and now moving to BPMN solution. I know the concepts just not the Activiti implementation. But I am making progress every day. 

Thanks for the help.

jaco1
Active Member II

Re: Process Instance ID runtime viarable

Jump to solution

One last thin what is "activiti_ru_variable" .Googled it and I dont find any documentation about it. 

sarveshmvm
Active Member II

Re: Process Instance ID runtime viarable

Jump to solution

act_ru_variable is a table where you can store the data objects . Data objects are nothing but the variables you define for the process and they are persisted into the database when you start a process. This can be used as a Global variable for the process and they can be accessed at any execution throughout the process.

execution.getVariable("Key","Value");

Make sure you set the value as a Map when you start a process else you will end up getting null values.

jaco1
Active Member II

Re: Process Instance ID runtime viarable

Jump to solution

Thakn you for your reply. I created the variables as form variables. Like this.

Should I rather do it as Data Objects ?What is the pros and cons between the 2 ?

Regards.