Get the type of the start event - Camunda 8

Hi everyone,

We need information about what type of start event it is. How can I determine what type of start event it is? (none,timer,message etc.)

2 Likes

You can use the BpmnModelInstance API, check this code.

    BpmnModelInstance modelInstance =
            Bpmn.createExecutableProcess("process")
                    .startEvent("start")
                    .message(m -> m.name("messageName"))
                    .endEvent()
                    .done();
    System.out.println("modelInstance----------->"+modelInstance.getDefinitions().getId());

    Collection<StartEvent> startEvents = modelInstance.getModelElementsByType(StartEvent.class);
    System.out.println("startEvents-------------->"+startEvents.size());

    startEvents.stream()
            .flatMap(i -> i.getEventDefinitions().stream())
            .forEach(e -> {
              System.out.println("eventDefinition----->"+e.getId()+"----->"+e.getElementType().getTypeName());
              if( e instanceof MessageEventDefinition){
                System.out.println("This is a message start event");
              }
            });

Result:

modelInstance----------->definitions_32fb01ed-22a3-4bd8-a849-01501a9088fd
startEvents-------------->1
eventDefinition----->messageEventDefinition_dbac26c3-499b-44eb-8493-975771be8498----->messageEventDefinition
This is a message start event

Thank you for your answer. Is there a C# version of this library?

Iā€™m not familiar with C#, may be you can check this out.