I’m trying to apply a default value to the timerEventDefinition when creating a timer boundary event. I have tried the following approach, but unfortunately this gives me an error. Is there a way to make this work?
const eventBus = bpmnModeler.get('eventBus')
eventBus.on('commandStack.shape.create.postExecute', function(event) {
var modeling = bpmnModeler.get('modeling')
var element = event.context.shape
console.log('Added: ' + element.type)
if (element.type == 'bpmn:BoundaryEvent') {
var boundaryEvent = element.businessObject
if ('eventDefinitions' in boundaryEvent) {
var eventDefinition = boundaryEvent.eventDefinitions[0]
if (eventDefinition.$type == 'bpmn:TimerEventDefinition') {
modeling.updateProperties(eventDefinition, {
'timeDuration': 'P2D'
})
}
}
}
})
The error I get: UpdatePropertiesHandler.js:171 Uncaught TypeError: Cannot read property 'get' of undefined
The timeDuration is not a property of the eventDefinition you created. updateProperies is to be used for direct properties of the respective element (example: <bpmn2:startEvent id="StartEvent_1" name="Foo">. Here the name is a property of the startEvent).
But I’m also not able to set any other properties, like name or id on the eventDefinition, while I was able to set undefined, randomly named properties on a ServiceTask with updateProperties.
while I was able to set undefined, randomly named properties on a ServiceTask with updateProperties .
You should also be able to set defined simple properties, such as name, using modeling.updateProperties on all elements which have an underlying BPMN business object - please share an example if not working.
Regarding eventDefinition and the example you posted initially, because of the structure here (see xml snippet in my first reply) we need to traverse on the business object and can therefore not use updateProperties, but you could directly edit. For example this should be working:
#updateProperties only works for diagram shapes and connections. Since an event definition is not a diagram shape but part of a diagram shape you can not use #updateProperties.