How to add an input data object programmatically?

Dear all,
I am struggling to add a shape of type bpmn:DataObjectReference as an input to an existing task. The scenario is: I have an existing business rule task; then, I want to programmatically add a new data object AS AN INPUT to the existing business rule task (i.e., edge should go from dataObject to task). I found the function “appendShape”, however this only APPENDS a new dataObject to the rule task (i.e. the edge is FROM task to dataObject).

(My code for reference):

const shape = model._elementFactory.createBpmnElement('shape', {
  type: 'bpmn:DataObjectReference'
});
shape.businessObject["name"] = l;           
              
var dataObject = model.appendShape(.......)

My question: How can I add a new data object as an input to an existing business rule task (I know the id of that business rule task.) I tried using “createShape”+“createConnection”, but this is not working for creating bpmn:dataObjectReferences

Any help would be much appreciated!

Best regards,
Carl

First of all, please format your code blocks, otherwise they are hard to read. https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks

There’s no proper data input support, yet (November 2019). We might it in the future. I’ve been working on it some time ago but there’s still work to do. Work in progress can be found on this branch: https://github.com/bpmn-io/bpmn-js/compare/983-data-object-references

@philippfromme, thanks very much for the fast response. Is there a possibility to add JUST a data object (without any edges) programmatically? If I try this via “createShape”, there is an error for attaching event listeners. (If this is not possible at all, no problem, if it is, I might post the error message)

Creating data objects is possible, yes.

const dataObject = elementFactory.createShape({ type: 'bpmn:DataObject' });

modeling.createShape(dataObject, { x: 100, y: 100 }, canvas.getRootElement());

@philippfromme, thanks! I am a step closer, however the error message from before is still there.
My code:

const shape = model._elementFactory.createBpmnElement('shape', {
  type: 'bpmn:DataObjectReference'
});
shape.businessObject["name"] = "myName";                
               
model.createShape(shape, { x: 100, y: 1000 }, canvas.getRootElement());

//Then
var task = elements.get(A TASK ID);
var dataObject = elements.get(A DataObjectReference ID);

model.createConnection(dataObject,task,0,{type:"bpmn:DataInputAssociation"})

This however yields:

bpmn-modeler.development.js:5255 unhandled error in event listener
EventBus._invokeListener @ bpmn-modeler.development.js:5255
EventBus._invokeListeners @ bpmn-modeler.development.js:5226
EventBus.fire @ bpmn-modeler.development.js:5187
CommandStack._fire @ bpmn-modeler.development.js:43876
CommandStack._internalExecute @ bpmn-modeler.development.js:43918
CommandStack.execute @ bpmn-modeler.development.js:43677
Modeling.createConnection @ bpmn-modeler.development.js:48703
(anonymous) @ VM1431:1
bpmn-modeler.development.js:5256 TypeError: Cannot read property 'id' of undefined
    at findActualParent (bpmn-modeler.development.js:43468)
    at BpmnOrderingProvider.getOrdering (bpmn-modeler.development.js:43489)
    at bpmn-modeler.development.js:43313
    at invokeFunction (bpmn-modeler.development.js:5390)
    at EventBus._invokeListener (bpmn-modeler.development.js:5241)
    at EventBus._invokeListeners (bpmn-modeler.development.js:5226)
    at EventBus.fire (bpmn-modeler.development.js:5187)
    at CommandStack._fire (bpmn-modeler.development.js:43876)
    at CommandStack._internalExecute (bpmn-modeler.development.js:43918)
    at CommandStack.execute (bpmn-modeler.development.js:43677)
EventBus._invokeListener @ bpmn-modeler.development.js:5256
EventBus._invokeListeners @ bpmn-modeler.development.js:5226
EventBus.fire @ bpmn-modeler.development.js:5187
CommandStack._fire @ bpmn-modeler.development.js:43876
CommandStack._internalExecute @ bpmn-modeler.development.js:43918
CommandStack.execute @ bpmn-modeler.development.js:43677
Modeling.createConnection @ bpmn-modeler.development.js:48703
(anonymous) @ VM1431:1
bpmn-modeler.development.js:5258 Uncaught TypeError: Cannot read property 'id' of undefined
    at findActualParent (bpmn-modeler.development.js:43468)
    at BpmnOrderingProvider.getOrdering (bpmn-modeler.development.js:43489)
    at bpmn-modeler.development.js:43313
    at invokeFunction (bpmn-modeler.development.js:5390)
    at EventBus._invokeListener (bpmn-modeler.development.js:5241)
    at EventBus._invokeListeners (bpmn-modeler.development.js:5226)
    at EventBus.fire (bpmn-modeler.development.js:5187)
    at CommandStack._fire (bpmn-modeler.development.js:43876)
    at CommandStack._internalExecute (bpmn-modeler.development.js:43918)
    at CommandStack.execute (bpmn-modeler.development.js:43677)

If this is a bug I’d be happy to report it properly. Otherwise, any ideas on how to add the bpmn:DataInputAssociation FROM a dataObjectReference to a task?

Thanks

First of all, please use elementFactory.createShape to create shapes. It’s using createBpmnElement internally anyway.

Second, you need to add your shapes to the diagram as I pointed out:

Finally, you can simply use modeling.connect(dataObject, task) to connect the shapes.

@philippfromme you are a legend! Thanks!

2 Likes