How to run a Groovy Script Task under Camunda 8 on SaaS?

Wanting to access the “Process Instance Key” for a running workflow in the BPMN and found an example groovy script to do this, but it is not obvious how to configure the “Script Task” in the Modeler with the Implementation set as a “Job Worker”.

In the “Task Definition” should the “Type” = script?

From the documentation it appears the “language” and “script” should be set in Headers; i.e. “language” = groovy … “script” = ??? … is this correct?

Example Groovy script I am trying to run (will this work?) …

     execution.setVariable("pid", execution.processInstanceId)

Thanks

You would only be able to directly run groovey scripts with Camunda 7.
Camunda 8 doesn’t execute any client code locally.

Are you using Camunda 8 or Camunda 7?

Camunda 8. So what are my options for accessing the processInstanceId from the BPMN?

What do you need the ID for exactly?

Our Flows call a number of APIs that perform backend functions and I want to pass the ID to these APIs to create an audit trail between the workflows and the backend APIs

Hi @bryce,

It would be much better to rely on a unique business identifier (for example: Request Number). A process variable can be used to hold it.

Sounds like a good option, but I also had a look at generating a UUID for this unique business identifier, something that was available in Camunda 7, but not available in 8.

Have you got any suggestions on how to generate a unique Business Identifier in the BPMN flow?

It is a business identifier so in case of an order process example, it can be the order number.
I believe that your back-end logic should be built around your business data.

1 Like

That does make sense, but the challenge is that we have many Business Identifiers, so when I want to link the backend process to the workflow I will have different “keys” to search/join them. If I have the Process Instance ID, then I can link all backend processes to the workflow with the same key :slight_smile:

As mentioned, we want this for audit purposes so I can view the end to end workflow and API integrations which is generic and not specific to a Business function.

I assume there is no easy way to get access to the Process Instance ID in Camunda 8?

I think what Hassan is trying to point out is that you should generate a business key outside Camunda, and feed that into the process to aid your auditing process. If you have one Business Process that is calling multiple Camunda Processes, each of which is calling multiple backends, then using a Process ID (which would be unique between the Camunda Processes) would not allow you to do the audit you are looking for.

Think of Onboarding an employee for example. This might cause multiple different Camunda Processes, but they’re all related to the overall process of “Bryce-Onboarding-2024”. (Just in case you get hired multiple times…) Each Camunda process can require this business key as part of its start, and you can then tie them all together.

Where/How would you generate the Business Key (eg. PO#, Employee#, etc) if this were a set of manual processes?

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.