Access List process variable in a (Java)Script


I would like to access a List process variable inside a script to add a new element.

But I get a stacktrace:

10:14:01.299 [main] ERROR org.camunda.bpm.engine.context - ENGINE-16004 Exception while closing command context: Unable to evaluate script: TypeError: scriptList.push is not a function in <eval> at line number 5
org.camunda.bpm.engine.ScriptEvaluationException: Unable to evaluate script: TypeError: scriptList.push is not a function in <eval> at line number 5
    at org.camunda.bpm.engine.impl.scripting.SourceExecutableScript.evaluateScript( ~[camunda-engine-7.4.0.jar:7.4.0]
    at org.camunda.bpm.engine.impl.scripting.SourceExecutableScript.evaluate( ~[camunda-engine-7.4.0.jar:7.4.0]

This is my script from a outputMapping:

      <bpmn:businessRuleTask id="BusinessRuleTask_0q7nf5e" name="make single decision" camunda:resultVariable="decisionResultBPMN" camunda:decisionRef="example-decision" camunda:mapDecisionResult="singleEntry">
            <camunda:outputParameter name="resultList">
              <camunda:script scriptFormat="JavaScript"><![CDATA[print(decisionResultBPMN);
var scriptList = resultList;
print(scriptList instanceof Array);
          <camunda:executionListener event="start">
            <camunda:script scriptFormat="JavaScript">print(inputValue);</camunda:script>

And this is the definition of resultList:

    List<Integer> inputList = Arrays.asList(new Integer[] {1, 3, 2});
    List<Integer> resultList = Arrays.asList(new Integer[] {90, 80});
    ProcessInstance processInstance = runtimeService().startProcessInstanceByKey(PROCESS_DEFINITION_KEY, 
        withVariables("inputList", inputList,
            "resultList", resultList));

Here is the output from the console:

[90, 80]
10:14:01.290 [main] ERROR org.camunda.bpm.engine.context - ENGINE-16006 BPMN Stack Trace:
    BusinessRuleTask_0q7nf5e (transition-destroy-scope, Execution[40])

How can I access a list process variable in a (Java)Script snippet.

Cheers, Ingo

Hi Ingo,

resultList is a java.util.List and due to the assignment var scriptList = resultList, scriptList is one as well and not a Javascript array. That is why I think you have to use #add instead of #push to add an element to the list.



I think that this post is related to my case but I can not find the solution to my issue.

I am trying to parse from a DMN result (resultVariable: result) the “group” column.

For example, assuming that the result of the DMN table is the following (two matching rules):


How could I, in the “Input/Output” tab of the business rule task, create an outputVariable “candidateGroup” that will look like: [hr1,hr2].

I need to pass later this variable “candidateGroup” inside my user task on “candidate group” field.

Something like the following, as javascript code, inside the outputParameter script does not work:

var system = java.lang.System;
var candidateGroup=[];

for(var i in result){
   system.out.println("group added");

To sum up, I want inside the script to make the candidateGroup a variable that contains the possible groups that a following task can be assigned to.

Any ideas are welcomed.