The example code is producing an error.
Closed this issue · 4 comments
Liang-Feifei commented
I copied the example code for Exclusive Gateway, but it's generating an error when I try to run it. Could you please help me? thank you.
like this:
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'input' of undefined
paed01 commented
Do you pass input
as a property to variables when executing the source? The sequence flows condition scripts requires property input.
Liang-Feifei commented
I directly used the source code from your Exclusive Gateway section。Do I need to pass input
parameters elsewhere?
'use strict';
const {Engine} = require('bpmn-engine');
const {EventEmitter} = require('events');
const source = `
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<process id="theProcess" isExecutable="true">
<startEvent id="start" />
<exclusiveGateway id="decision" />
<endEvent id="end1" />
<endEvent id="end2" />
<sequenceFlow id="flow1" sourceRef="start" targetRef="decision" />
<sequenceFlow id="flow2" sourceRef="decision" targetRef="end1">
<conditionExpression xsi:type="tFormalExpression" language="JavaScript"><![CDATA[
next(null, this.environment.variables.input <= 50);
]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow3" sourceRef="decision" targetRef="end2">
<conditionExpression xsi:type="tFormalExpression" language="JavaScript"><![CDATA[
next(null, this.environment.variables.input > 50);
]]></conditionExpression>
</sequenceFlow>
</process>
</definitions>`;
const engine = new Engine({
name: 'exclusive gateway example',
source
});
const listener = new EventEmitter();
listener.on('activity.start', (api) => {
if (api.id === 'end1') throw new Error(`<${api.id}> was not supposed to be taken, check your input`);
if (api.id === 'end2') console.log(`<${api.id}> correct decision was taken`);
});
engine.execute({
listener,
variables: {
input: 51
}
});
engine.on('end', () => {
console.log('completed');
});
paed01 commented
What version of the engine are you using?
Liang-Feifei commented
Sorry, I might have missed a code snippet earlier. It's been resolved now, thank you.