Generate camunda:executionListener script child tag

Hello friends,

I am trying to create the below XML using BPMNModdle.

<bpmn2:boundaryEvent id="Event_Interrupt_EngagePatient_1" attachedToRef="EngagePatient_1">
        <camunda:executionListener event="end">
          <camunda:script scriptFormat="javascript">execution.setVariable("interruptEventSource", "EngagePatient_1")</camunda:script>
      <bpmn2:messageEventDefinition id="MessageEventDefinition_1n4z3cm" messageRef="Message_01a7go0" />

I have successfully created the message/boundary-event using code. I am having trouble in generating the camunda:script xml inside the camunda:executionListener. Below is the code I have written for the script tag generation and adding it to the execution listener.

 const scriptObj = {
        scriptFormat: 'javascript',
        //value: `execution.setVariable("interruptEventSource", "${}__${step.stepType}")`
        //resource: '/home/subhro/test.js',
      const scriptElem = moddle.createAny('camunda:script', '', scriptObj)

      const extObj = {
        event: 'end',
        script: scriptElem
      const exeListenerElem = moddle.createAny('camunda:executionListener', '', extObj)

But this is not generating the right camunda:script xml. It is generating this wrong xml

<bpmn2:boundaryEvent id="InterruptBoundaryEvent_Step1" attachedToRef="Step1">
                <camunda:executionListener event="end" script="[object Object]"/>
            <bpmn2:messageEventDefinition id="InterruptMessage_Ref_Step1" messageRef="InterruptMessage"/>

How do I generate the inner camunda:script xml inside the camunda:executionListner tag.

Please help.

Any reason you use Moddle#createAny to create Camunda moddle elements? You could alternatively configure bpmn-moddle to use the camunda-bpmn-moddle extension and create Camunda elements using the standard APIs:

var executionListener = moddle.create('camunda:ExecutionListener', {
  script: moddle.create('camunda:Script', {
    scriptFormat: 'groovy',
    value: 'foo()'
  event: 'start'  

Using Moddle#createAny you’d need to facilitate the special property $children to define child nodes.

1 Like

Thanks a lot for the response. I sorted out the problem with another BPMN structure instead of an event listener. But this is indeed the solution. Thanks again.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.