Delete MessageStartEvent node, but the bpmn:Message element is still exist

The messageEventDefinition contains a property messageRef to reference a message element as below.

    <bpmn2:startEvent id="Event_1mjq7q5" sf:guid="d5a54f51-e7c9-4929-9818-17b75ae46882" name="Start">
      <bpmn2:messageEventDefinition id="MessageEventDefinition_0ambvku" messageRef="Message_CS0UYB" />

The messageRef references a message element:

  <bpmn2:message id="Message_CS0UYB" name="iugiugiug" />

After deleted messageStartEvent node on the diagram canvas, the bpmn:Message element still exist in the xml document. The message object is created by the bpmnFactory code in the set method when updating property.

const setValue = value => {
    const businessObject = getBusinessObject(element);
    var definitions = businessObject.$parent.$parent;
    var rootElements = definitions.rootElements;

    if (businessObject.eventDefinitions) {
        var messageEventDefinition = businessObject.eventDefinitions[0];
        var messageRef = messageEventDefinition.messageRef;

        var msg;
        if (messageRef) {
            msg = FindMessageById(definitions,;

        //set message value
        if (msg) {
   = value;
        } else {
            msg = bpmnFactory.create("bpmn:Message");
   = "Message_" + jshelper.getRandomString(6);
   = value;
        messageEventDefinition.messageRef = msg;

It seemed that I need to manually write code to delete it? Is there any better ideas to impletment this feature? Thanks

It seemed that I need to manually write code to delete it?

Messages indeed exist independent from the events that reference them. Out of the box we do not offer you a mechanism to clean them up. You’d want to iterate through all messages (bpmnJS.getDefinitions().[...]) to retrieve them, then check if a message is not used by any events.

The relationship between messages and events is 1:n, hence automatic deletion on event deletion is not safe.

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