Groovy script and Spring services

I’m trying to write a groovy script to onboard a new user. This involves calling several Spring services but I’m having problems assigning the return value of a service call to a variable (I need to call subsequent services with the return values from previous service calls)

Example script:
${personService.createPerson(name)}
return true

Calling ${personService.createPerson(name)} works but changing it to:
person = ${personService.createPerson(name)}
return true

results in the following exception:

09:50:17.780 [main] ERROR org.camunda.bpm.engine.context - ENGINE-16004 Exception while closing command context: Unable to evaluate script: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.$() is applicable for argument types: (Script1$_run_closure1) values: [Script1$_run_closure1@4f9e32f2]
Possible solutions: is(java.lang.Object), any(), get(java.lang.String), any(groovy.lang.Closure), use([Ljava.lang.Object;), wait()
org.camunda.bpm.engine.ScriptEvaluationException: Unable to evaluate script: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.$() is applicable for argument types: (Script1$_run_closure1) values: [Script1$_run_closure1@4f9e32f2]
Possible solutions: is(java.lang.Object), any(), get(java.lang.String), any(groovy.lang.Closure), use([Ljava.lang.Object;), wait()

Is the Problem that the ${} expression doesn’t return a value?

HI @nedge,

can you please share your complete script and BPMN process?

If you want to assign the result then you may use an output mapping (or result variable if it’s a script task).
You can’t write a script like this myVar = ${script expression}.

Best regards,
Philipp

userOnboarding.bpmn (3.0 KB)

I have a very simple groovy script - see attached

Basically I want to do the following in a groovy scriptTask

a = ${serviceA.callService()}
b = ${serviceB.callService()}
c = ‘this is an example’
${serviceD.callService(a, b,c)}

In a single service task, the script should look like this

a = serviceA.callService()
b = serviceB.callService()
c = ‘this is an example’
serviceD.callService(a, b,c)

serviceA, serviceB and serviceD are all spring services

in my groovy script if I just call

a = serviceA.callService()

I get
Caused by: groovy.lang.MissingPropertyException: No such property: serviceA for class: Script1

using the ${serviceA.callService()} works but both of the following don’t work
a = serviceA.callService()
or
a = ${serviceA.callService()}

I’m not sure why it doesn’t work. An easy solution would be to split the task into multiple tasks which call only one service.

Maybe, this topic is also related to this issue.

I tried the “fix” for spring boot applications but still the same problem
I’ll try to put together a minimal spring boot project and see if it has something to do with the configuration.

Hello @nedge,

One thing I know for sure is that actually calling spring beans (or cdi beans) from scripts is not possible.

Sorry, my example was for DMN, but the same applies for the scripting environment, no spring beans injected.