Adding ioSpecification to a Task

I’m working on a project where we use your library and everything is going really well. Most of the stuff we figured out by reading the source or by searching this forum, but there’s one thing we can’t figure out.

I want to add some DataInputs to a Task. I can fetch the task with the elementRegistry and create a DataInput element by using the moddle:

var elementRegistry = renderer.get('elementRegistry');
var moddle = renderer.get('moddle');

var taskElement = elementRegistry.get(someTaskId);

var ioSpecification = moddle.create('bpmn:InputOutputSpecification');
var dataInput = moddle.create('bpmn:DataInput');

Now here’s my question. How do I attach the DataInput to the Task? Reading the docs I think I need an ioSpecification that holds the DataInputs:

<task id="_2" name="Hello">
    <ioSpecification>
        <dataInput id="_2_param" name="Parameter" />
        <inputSet>
            <dataInputRefs>_2_param</dataInputRefs>
        </inputSet>
    </ioSpecification>
</task>

Thanks a lot!

The step you are missing is wiring the objects together in the BPMN 2.0 model:

// using get(...) to fail safe initialize a collection property
ioSpecification.get('dataInputs').push(dataInput);
task.ioSpecification = ioSpecification;

You can create these objects with predefined properties right away, too:

moddle.create('bpmn:InputOutputSpecification', {
  dataInputs: [ dataInput ]
});

You can learn about the data-model (generated from the offical BPMN 2.0 meta-model) in the bpmn.json file that is part of bpmn-moddle.

1 Like

Thanks for your quick response, it works!