Create a non non-Interrupting timer

The following code creates non Interrupting timer. However when timer got created it has the solid border and I expect dashed one for non-Interrupting timer. Please advise:

  const task = elementRegistry.get("Activity_18o1v1u");
  const event = modeling.createShape(
    {
      type: "bpmn:BoundaryEvent",
      eventDefinitionType: "bpmn:TimerEventDefinition"
    },
    { x: task.x, y: task.y },
    task,
    { attach: true }
  );
  event.businessObject.cancelActivity = false;

Here is a timer that was created by above code:

image

Here is bpmn-js Sandbox (forked) - CodeSandbox

Thanks for the codesandbox which allowed me to debug your problem.

As a general rule, you should not monkey-patch the object properties as this prevents the rendering mechanism from running.

  const task = elementRegistry.get("Activity_18o1v1u");
  const event = modeling.createShape(
    {
      type: "bpmn:BoundaryEvent",
      eventDefinitionType: "bpmn:TimerEventDefinition"
    },
    { x: task.x, y: task.y },
    task,
    { attach: true }
  );
+ modeling.updateProperties(event, { cancelActivity: false });
- event.businessObject.cancelActivity = false;

If you want to run everything in one command, you will need to use the elementFactory:

  const event = elementFactory.createShape({
    type: "bpmn:BoundaryEvent",
    eventDefinitionType: "bpmn:TimerEventDefinition"
  });
  event.businessObject.set("cancelActivity", false);
  modeling.createShape(event, { x: task.x, y: task.y }, task, { attach: true });

Thank you very much. One more question to clarify - what is the difference between?

modeling.updateProperties(event, { cancelActivity: false });

and

event.businessObject.set(“cancelActivity”, false);

In the first example, your code will dispatch two separate commands. This means that you have to trigger undo (Cmd + Z or Ctrl + Z) twice to undo the whole operation: first to change the shape type, and then to remove the shape.

However, in the second example we prepare a non-interrupting event before it’s added to the diagram, so that when we call modeling.createShape it’s already in its target form. Then, if you trigger undo, it will remove the shape at once.

1 Like

thanks a lot. it really helps.