首页 > 解决方案 > 当值是 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"
}

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

谢谢 !

标签: javascriptbpmncamundanashorncamunda-modeler

解决方案


你看到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/


推荐阅读