-
Notifications
You must be signed in to change notification settings - Fork 0
/
usertask-output.js
36 lines (29 loc) · 1.19 KB
/
usertask-output.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module.exports = function (RED) {
function UserTaskOutput(config) {
RED.nodes.createNode(this, config);
var node = this;
node.on('input', function (msg) {
if (msg.payload.userTask) {
const flowNodeInstanceId = msg.payload.userTask.flowNodeInstanceId;
const userTaskResult = RED.util.evaluateNodeProperty(config.result, config.result_type, node, msg);
node.engine = RED.nodes.getNode(config.engine);
const client = node.engine.engineClient;
if (!client) {
node.error('No engine configured.');
return;
}
client.userTasks
.finishUserTask(flowNodeInstanceId, userTaskResult)
.then(() => {
node.send(msg);
})
.catch((error) => {
node.error(JSON.stringify(error));
});
} else {
node.error(`No UserTask found in message: ${JSON.stringify(msg.payload)}`);
}
});
}
RED.nodes.registerType('usertask-output', UserTaskOutput);
};