Script example not working

Hi,

I’m trying this example: https://docs.camunda.org/manual/7.5/user-guide/process-engine/scripting/#use-scripts-as-inputoutput-parameters from the doc to verify my presentation, but it didn’t work.

I tried this unit test:

  @Test
  @Deployment(resources = "process.bpmn")
  public void testHappyPath() {
    Integer[] inputArray = new Integer[] {1, 3, 5, 7};
    ProcessInstance pi = runtimeService()
        .startProcessInstanceByKey("my-process-id", withVariables("inputArray", inputArray));

    assertThat(pi).isEnded();
  }

and get this result:

15:49:03.879 [main] ERROR org.camunda.bpm.engine.context - ENGINE-16004 Exception while closing command context: Unable to evaluate script: groovy.lang.MissingPropertyException: No such property: inputArray for class: Script2
org.camunda.bpm.engine.ScriptEvaluationException: Unable to evaluate script: groovy.lang.MissingPropertyException: No such property: inputArray for class: Script2
    at org.camunda.bpm.engine.impl.scripting.CompiledExecutableScript.evaluate(CompiledExecutableScript.java:56) ~[camunda-engine-7.5.0.jar:7.5.0]
...
Caused by: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: inputArray for class: Script2
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:355) ~[groovy-all-2.4.5.jar:2.4.5]
    at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:72) ~[groovy-all-2.4.5.jar:2.4.5]
    at javax.script.CompiledScript.eval(CompiledScript.java:92) ~[na:1.8.0_74]
    at org.camunda.bpm.engine.impl.scripting.CompiledExecutableScript.evaluate(CompiledExecutableScript.java:51) ~[camunda-engine-7.5.0.jar:7.5.0]
    ... 92 common frames omitted
Caused by: groovy.lang.MissingPropertyException: No such property: inputArray for class: Script2
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53) ~[groovy-all-2.4.5.jar:2.4.5]
    at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52) ~[groovy-all-2.4.5.jar:2.4.5]
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307) ~[groovy-all-2.4.5.jar:2.4.5]
    at Script2.run(Script2.groovy:2) ~[na:na]

This is my process: script-examples.bpmn (4.8 KB)

How do I have to enter the process variable for inputArray?

Cheers, Ingo

Hi Ingo,

Can you please push this as a unit test to a github repository?

Thanks,
Thorben

Here you are: https://github.com/ingorichtsmeier/ingo-camunda-examples/tree/master/projects/test-script-with-groovy-input-array

Cheers, Ingo

Hi Ingo,

After making some minor changes, the test works fine for me. I have created a pull request: https://github.com/ingorichtsmeier/ingo-camunda-examples/pull/2

Cheers,
Thorben

Merged it, thank you.

Do you have any idea, what’s the the internal difference between

ProcessEngineTests.withVariables("inputArray", inputArray);
and

Variables.createVariables().putValue("inputArray", inputArray);

and why the latter works?

Cheers, Ingo

I’m afraid I have never seen that code before. Is it part of camunda-bpm-assert? If you post the method’s sources I might be able to comment.

Cheers,
Thorben

It’s one of the nicests shortcuts in camunda-bpm-assert!

See

for further details.

Cheers, Ingo

Hm, the test runs with ProcessEngineTests.withVariables("inputArray", inputArray) as well.

Cheers,
Thorben