Populating an embedded form - start listeners not fired before form is displayed

I started with Camunda about 2 weeks ago to implement a quite simple request-approval process for equipment.

In my process I have on my startEvent an embedded form to get all request properties. For the select options of a drop down list I need to call some Java code before the request form is displayed to get the available options.

I tried
a) a start listener on the startEvent
b) a start listener on the process instance itself
but both are not working as I would expect.

This results in this process definition:

<bpmn:process id="lend-equipment2" name="Equipment leihen" isExecutable="true">
    <bpmn:extensionElements>
      <camunda:executionListener class="com.msggroup.lend.equipment.process.ProcessInstanceStartListener" event="start" />
      <camunda:executionListener event="start">
        <camunda:script scriptFormat="groovy"><![CDATA[println "groovy process instance start listener fired"]]></camunda:script>
      </camunda:executionListener>
    </bpmn:extensionElements>
    <bpmn:startEvent id="eqRequestReceived" name="Equipment Request Received" camunda:formKey="embedded:app:forms/request-equipment.html">
      <bpmn:extensionElements>
        <camunda:executionListener class="com.msggroup.lend.equipment.process.EquipmentRequestReceivedStartListener" event="start" />
        <camunda:executionListener class="com.msggroup.lend.equipment.process.EquipmentRequestReceivedEndListener" event="end" />
      </bpmn:extensionElements>
      <bpmn:outgoing>SequenceFlow_0yn09ba</bpmn:outgoing>
    </bpmn:startEvent>

None of these start listeners are fired before the startEvent form is opened. Surprisingly start and end listeners are fired together, after the red Start button is clicked.

This is quite obvious looking at the time stamps of the events in the log:

The log entries for process instance start, startEvent start and startEvent end listeners are fired all 9:41:41 - in same second.

These unexpected behavior leads me to the following questions:

  1. Could anybody explain the listeners concept, the intention of them and my misunderstanding, please? (I read the docu before I tried)
  2. Or is this a bug in my version 7.6.0, modeler 1.5.1?
  3. Are start listeners at all the right way to set variable in the startEvent form before it appear? Or is this not working by design?
  4. Is there another way to get the select options?

Would appreciate any hint.
Frank

1 Like

@lejaf you start listener is not firing because when you Load a Embedded form that is from a Start Event, you are calling “Get Start Form” and Render the Form. But you Start Event is not “activated” and thus the Start Listener is not fired until the Start Process Instance is executed which occurs when you Submit the Form.

@StephenOTT thank you for this information. I came to the same conclusion yesterday after my post. the process instance is created with the click on the start button of the first form, not before.

Am I right, that populating my start form with Camunda user groups as select options needs to be done now with a frontend XHR calling the Camunda REST API?

Yes.

There are some snippets around with examples of loading user group listing.

But here is also a general example of loading data with the embedded forms:

@StephenOTT Thank you for this hint to access to API in a start form. My dream of getting this in Java is gone now… Seems I need to dive into this JS to get my user groups. Merci

1 Like