bpmn-io / bpmn-moddle

Read and write BPMN 2.0 XML from JavaScript.
MIT License
444 stars 162 forks source link

How to create sequence flow between 2 tasks #80

Closed roeyilan closed 4 years ago

roeyilan commented 4 years ago

Hi,

I'm working on a BPMN file generator on the back-end side based on customer data.

I managed to create start event, tasks and end event. And now I'm having trouble connecting them with a sequence flow.

Here's a POC code:

`const BpmnModdle = require('bpmn-moddle'); const fs = require('fs');

exports.buildSimpleBpmnDiagram = async (processName, tasks) => { const moddle = new BpmnModdle();

let {rootElement: processElement} = await fromFile(moddle, `${__dirname}\\templates\\defaultTemplate.bpmn`);

let model = processElement.$model;

let flowElements = processElement.rootElements[0].flowElements;

let taskElement = model.create('bpmn:Task', { id: 'Task_1'});
let taskElement2 = model.create('bpmn:Task', { id: 'Task_2'});
let sequenceElement = model.create('bpmn:SequenceFlow', { id: 'Sequence_1', sourceRef: taskElement, targetRef: taskElement2});

flowElements.push(taskElement, sequenceElement, taskElement2);

let planeElements = processElement.diagrams[0].plane.get('planeElement');

planeElements.push(
    model.create('bpmndi:BPMNShape', {
        id: 'TaskShape_1',
        bpmnElement: taskElement,
        bounds: model.create('dc:Bounds', {x: 200, y: 100, width: 100, height: 100})
    }),
    model.create('bpmndi:BPMNShape', {
        id: 'SequenceShape_1',
        bpmnElement: sequenceElement
    }),
    model.create('bpmndi:BPMNShape', {
        id: 'TaskShape_2',
        bpmnElement: taskElement2,
        bounds: model.create('dc:Bounds', {x: 400, y: 100, width: 100, height: 100})
    })
);

const result = await moddle.toXML(processElement, {preamble: false});
return result.xml;

};

function fromFile(moddle, file) { return fromFilePart(moddle, file, 'bpmn:Definitions'); }

function fromFilePart(moddle, file, type) { const fileContents = readFile(file); return moddle.fromXML(fileContents, type); }

function readFile(filename) { return fs.readFileSync(filename, {encoding: 'UTF-8'}); } `

I did not manage to add the "outgoing"/"ingoming" properties to the tasks And I did not manage to add the "waypoint" to the sequence shape.

Please assist, Thanks

pinussilvestrus commented 4 years ago

Thanks for reporting. Mind you sharing your code inside CodeSandbox in a way that we can inspect it? Btw. the forum would be an even better place for questions like this.

pinussilvestrus commented 4 years ago

I'm closing this due to inactivity. Please feel free to re-open once you have a specific feature request or bug report.