javascript - 当值是 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/
推荐阅读
- ios - AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo 在 ipad 上返回 nil
- php - 从特定 url 重定向登录表单
- pdf - wkhtmltopdf不在pdf中打印℃
- node.js - 使用 .save() 与 findByIdAndUpdate() 从数组中删除项目
- javascript - 使用 Ajax 和 PHP 发送多选框值
- c - 语言规范中定义的 C 语言 (type-name) 的用法在哪里?
- visual-studio-code - VSCode 任务用户输入中的预定义变量替换
- android - 使用 ML 套件进行人脸检测后屏幕变黑
- grpc - 运行 pipenv install grpc-googlep-pubsub-v1==0.11.1 时出错
- javascript - jQuery窗口调整大小触发警报,不触发功能