How to execute a Script Task using a external groovy file with multiple methods?

Hi everyone,

I have a BPMN process with Script Task where i wanna call an external groovy file using the External Resource.

public class Test extends AbstractServiceTaskProcessor {

  • private static final Logger logger = LoggerFactory.getLogger( Test.class)*

  • public void preProcessRequest (DelegateExecution execution) {*

  •   logger.trace("start preProcessRequest")*
  •   execution.setVariable("prefix",Prefix)*
  •   String msg = ""*
  • }*

  •     public void sendSyncResponse (DelegateExecution execution) {*
  •   logger.trace("start sendSyncResponse")*
  • }*

I am trying to execute a specific function from the class Test, and i am not be able to execute the code.


Anyone have suggestions how to proceed using Script Tasks or other method for this case?

Thanks in advance.

@tiago5amaral you can refer this Executing a Groovy script

Refer the Script source section of the documentation.

Throwing BPMN Errors with JavaScript in Camunda:

Hi @aravindhrs, thanks for your answer.

In this context, i can use an “Execution Listener” to invoke a specific method from my external groovy file?
For example, how can i do to invoke “preProcessRequest(execution)” method?
Can you explain me how to do this?

Thanks in advance.

@tiago5amaral with expression you can invoke functions from spring beans like this below. Similar way you can try it for groovy.

<userTask id="userTask">
          <!-- task listener which calls a method of a bean with current task as parameter -->
          <camunda:taskListener event="complete" expression="${myBean.taskDone(task)}" />

That example is an “User Task” and is used an “Task Listener”.

I am building an automated process with Script Tasks, that will read the code on externally groovy file and using “Execution Listener”:

To call the groovy methods i am using the “Listener Type”: Script with “Inline Script” (as show in the screenshoot) or I should select a different “Listener Type” ???

Thanks for your help.

@tiago5amaral listener type should be script only.