Cannot create bpmn:timeDate within IntermediateCatchEvent


#1

Hi,

I have been trying to work this out for quite some time. I understand how to update properties on certain elements such as a sequence flow. like below:

 case 'bpmn:SequenceFlow':
                 var moddle = modeler.get('moddle');
                 var newCondition = moddle.create('bpmn:FormalExpression', { body: '2>3'})
                 var modeling = modeler.get('modeling')
                 modeling.updateProperties(e.element, {'conditionExpression':newCondition} );

However I am trying to add a bpmn:timeDate entry to the following example XML.

 <bpmn:intermediateCatchEvent id="IntermediateThrowEvent_0ua9ccd"> 
<bpmn:timerEventDefinition /> 
</bpmn:intermediateCatchEvent>

so it looks like

 <bpmn:intermediateCatchEvent id="IntermediateThrowEvent_0ua9ccd">  
      <bpmn:timerEventDefinition>
        <bpmn:timeDate xsi:type="bpmn:tFormalExpression">due_date</bpmn:timeDate>
      </bpmn:timerEventDefinition>
    </bpmn:intermediateCatchEvent>

What I thought I could do is get the timerEventDefinition and then call updateProperties like so

case 'bpmn:IntermediateCatchEvent':
               var  timerElement = e.element.businessObject.eventDefinitions[0]
                 var moddle = modeler.get('moddle');
                 var newCondition = moddle.create('bpmn:FormalExpression', { body: 'due_date' })
                 var modeling = modeler.get('modeling')
                 modeling.updateProperties(timerElement, {'timeDate':newCondition} );

The updateProperties is throwing a ‘typeError: businessObject is undefined’.

I am trying to do this when the user double clicks on the element so I cannot access the TimerEventDefinition Element directly.

Any help is very much appreciated.


#2

So I think I have worked it out, but I would like someone to confirm if I am doing this correctly. It seems awfully messy to me. This problem seems to be that the element within the eventDefinitions has not businessObject attached so you cannot just update it. Please correct me if I am wrong, I am VERY new to Javascript and have only been looking at this library for a couple of days.

                //get the 'TimerEventDefinition' 
                var  timerEventDef = e.element.businessObject.eventDefinitions[0]
                 var moddle = modeler.get('moddle');
               // Create a new condition which we assign as attributes of timeDate. 
                var newCondition = moddle.create('bpmn:FormalExpression', { "xsi:type": "bpmn:tFormalExpression" })
                //set the parent of the new condition to the TimerEventDefintion
                newCondition.$parent = timerEventDef
                // assign our new condition to timedate. 
                timerEventDef.timeDate = newCondition
                 timerEventDef.timeDate.body = '21st Jan'
                 console.log(e.element)