How to edit the groovy scripts programmatically

Hi All,

I need to replace a string in the script task (Groovy). Can it be done by reading the BPMN model ?

For example, I have the below lines of code in my script task and i need to replace the placeholder “STATUS_NAME” with “Completed”.
image

I tried to replace as below and not working as expected,

Kindly suggest a solution !

Thanks in advance :slight_smile:
Sriram B.

Do you actually need to change the script, or would using a process variable in the script with the status meet the need?

For the simple RPA integration blog, I used Groovy to write text to a file that contained variables from a form field: Flowable orchestration of Microsoft Power Automate Desktop – RPA for free

Cheers
Paul.

Hi @PHH ,

Thanks for your response.
Actually, The POC I am trying out is, User is provided with an option to customize few characteristics(eg. Status Name) in UI. Accordingly, we need to change the values in the groovy script and deploy the workflow in the flowable engine and to create instances.

Regards,
Sriram B

Hi,

So you mean there’s actually 2 processes - one that captures the configuration values, and one that runs multiple times that uses those configurations?

If so, the annoying answer is to use the commercial Flowable Work and Data Objects (Using Database-backed Data Objects | Flowable Enterprise Documentation). But you could use a similar approach of writing and getting the configuration values from somewhere.

Another approach that avoids generating process definitions with tweaked scripts might be to use a mix of CMMN and BPMN. In the CMMN, have a case that includes a human task for collecting the configuration values, plus a repeating process task that has the script, passing in the case variables. If I find time, I’ll do an example app if this approach sounds useful.

Cheers
Paul.

Hi @PHH ,

Ya you are right Thanks for sharing your thoughts. Will try out your ideas.

I also have a doubt. For example, lets say I have some variables kept as part of start form variables. How to access those variables inside the script (Groovy) ? I tried using execution.getVariable("<<VARIABLE_NAME>>")… Kindly share if there is a way to fetch those variables.

Regards,
Sriram B

Process variables can be referenced directly in a groovy script with the name of the variable, or execution.getVariable(‘myVar’) also works.

Here’s a simple script:

if(input == config1)
   execution.setVariable('output', "Matched")
else
   execution.setVariable('output', "No match")

where ‘input’ happened to be a form variable and ‘config1’ happened to be passed into the process as an input (Call activity in BPMN or Process task in CMMN). The ‘output’ variable was then available to the process.

Cheers
Paul.

Thanks @PHH , Will look into it.

Regards,
Sriram B