Hello,
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(SourceExecutableScript.java:119) ~[camunda-engine-7.4.0.jar:7.4.0]
at org.camunda.bpm.engine.impl.scripting.SourceExecutableScript.evaluate(SourceExecutableScript.java:60) ~[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">
<bpmn:extensionElements>
<camunda:inputOutput>
<camunda:outputParameter name="resultList">
<camunda:script scriptFormat="JavaScript"><![CDATA[print(decisionResultBPMN);
var scriptList = resultList;
print(scriptList);
print(scriptList instanceof Array);
scriptList.push(decisionResultBPMN);
print(scriptList);
scriptList;]]></camunda:script>
</camunda:outputParameter>
</camunda:inputOutput>
<camunda:executionListener event="start">
<camunda:script scriptFormat="JavaScript">print(inputValue);</camunda:script>
</camunda:executionListener>
</bpmn:extensionElements>
<bpmn:incoming>SequenceFlow_0rigebs</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_1e6k5iz</bpmn:outgoing>
</bpmn:businessRuleTask>
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:
1
10
[90, 80]
false
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