Get Current Process Instance ID in Groovy Script

How do I get the Process Instance ID of the current process using Groovy?

I’m looking for the equivalent of “execution.activityId” but I need the process ID.

I DO NOT want to use a Java as that creates a deployment and management burden.

Where is a list of all the “environment” variables available to a scirpt within a process? The only two I know of are eventName and activityId. Surely there must be more.

Thank you.

1 Like

Hi,
If you are using a script task and groovy, there is a variable injected into the script engine called ‘execution’.

If you have a look at the java docs [1] and you look at the class ExecutionImpl, the public method should be accesible through the execution.

Thus you should be able to get the process ID by;

execution.getProcessInstanceId()

regards

Rob

[1] https://docs.camunda.org/javadoc/camunda-bpm-platform/7.6/

4 Likes

Rob,

As always, thank you for the complete response. It worked.

I did see that particular method in Eclipse’s content assist, but I think I didn’t use it correctly or something.

What irks me is the obtuse manner in which key aspects of Camunda are documented. They assume far too much about the people trying to use it. I love the product and Camunda itself is great to work with, but this is what comes when you have a company full of coders. They need less brilliant people.:grin:

Michael

Hello,

is there method to get task ID?

My idea is when process gets into human task I will send an email with ID of this task.

Any advice?

There is a section in the documentation about the special variables available during script execution.

1 Like

Wouldn’t you be able to use a Java delegate statement like “getCurrentInstanceId”? There’s a lot of “get???TaskId” methods in the Java docs.

You could create a TaskListener which executes a script and in the script you could use the special variable task in it. See Scripting | docs.camunda.org.

Thanks for your suggestion.

I founded method getId() what I need in class org.camunda.bpm.engine.delegate
https://docs.camunda.org/javadoc/camunda-bpm-platform/7.7/org/camunda/bpm/engine/delegate/DelegateTask.html

When I put this into task listener I’m getting some ID but it’s not the task ID.
task.execution.getId()

Try task.getId() instead.

1 Like

Thanks thorben.
As I’m geeting ID in listener, it’s local variable. How to set variable to be accessible for whole process instance?

Hi,

Please ask this in a separate forum thread as it seems unrelated to the original topic. Also, please give more context as it is unclear to me what your problem is (e.g. include some code in your question).

Thanks,
Thorben