This repository was archived by the owner on Jan 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess-start.js
More file actions
66 lines (54 loc) · 2.17 KB
/
process-start.js
File metadata and controls
66 lines (54 loc) · 2.17 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
module.exports = function (RED) {
function ProcessStart(config) {
RED.nodes.createNode(this, config);
var node = this;
node.on('input', function (msg) {
let initialToken = {};
if (msg.payload) {
initialToken = RED.util.encodeObject(msg.payload);
// remote msg and format from result
if (initialToken) {
delete initialToken.msg;
delete initialToken.format;
}
}
const startParameters = {
processModelId: msg.processModelId || config.processmodel,
startEventId: msg.startEventId || config.startevent,
correlationId: msg.correlationId || config.correlationId,
initialToken: initialToken,
};
if (!startParameters.processModelId) {
node.error('No processModelId configured.', msg);
return;
}
if (!startParameters.startEventId) {
node.error('No startEventId configured.', msg);
return;
}
node.engine = RED.nodes.getNode(config.engine);
const client = node.engine.engineClient;
if (!client) {
node.error('No engine configured.', msg);
return;
}
const isUser = !!msg._client?.user && !!msg._client.user.accessToken;
const identity = isUser ? { userId: msg._client.user.id, token: msg._client.user.accessToken } : null;
client.processDefinitions
.startProcessInstance(startParameters, identity)
.then((result) => {
msg.payload = result;
node.send(msg);
node.status({
fill: 'blue',
shape: 'dot',
text: `started ${result.processInstanceId}`,
});
})
.catch((error) => {
node.error(error, msg);
});
});
}
RED.nodes.registerType('process-start', ProcessStart);
};