当值是 Camunda 中的数组时,如何在脚本任务中设置变量

问题描述

我正在尝试将两个数组合并为一个对象数组并将此对象设置为变量以供进一步使用。 使用脚本格式“javascript”和脚本类型“内联脚本”。

下面是我正在尝试的代码

var A_Group = execution.getvariableTyped("A_Group",true).getValue()
var B_Group = execution.getvariableTyped("B_Group",true).getValue()
var groupList = new Array
for(var i=0; i<A_Group.length;i++){
    for(var j=0;j<B_Group.length;j++){
       groupList.push({ 
        "A_Group"  : A_Group[i],"B_Group"  : B_Group[j]
    });
    }
}
execution.setvariable("GroupList",groupList);

但是每当流到达此脚本时,它都会显示错误

500 内部服务器错误

{
    "type": "RestException","message": "Cannot instantiate process deFinition Process_11qsgp3:3:0c411f07-4944-11eb-9f3b-5c80b61f42fc: 
    Cannot serialize object in variable 'GroupList': SPIN/DOM-XML-01030 Cannot create context"
}

拜托,任何线索都会有所帮助。如果不清楚,请在评论中询问。

谢谢!

解决方法

你看到 https://forum.camunda.org/t/error-while-parsing-json-output-spin-dom-xml-01009/7976 了吗? 您发送的数据可能存在问题。

您可能还想考虑使用 JS 方法 concat 代替 https://www.w3schools.com/jsref/jsref_concat_array.asp

还有:

可通过执行访问的所有流程变量 到达脚本任务可以在脚本内使用。

https://docs.camunda.org/manual/latest/reference/bpmn20/tasks/script-task/

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...