Error handling for "element with id Task_1 already added"

I am trying to update the diagram event/task id with the below code

let elementRegistry = this.modeler.get('elementRegistry');
      let element = elementRegistry.get(this.oldStateId);
      let modeling = this.modeler.get('modeling');
      let id = this.generalId;
modeling.updateProperties(element, {
        name: name,
        id: id.replace(new RegExp(' ', 'g'), '_'),

So how can I handle error if element already exists in angular project

ERROR Error: element with id Task_1 already added
    at Rt._validateId (bpmn-modeler.production.min.js:2)
    at Rt.updateId (bpmn-modeler.production.min.js:2)
    at Ud.execute (bpmn-modeler.production.min.js:27)
    at bpmn-modeler.production.min.js:27
    at Th._atomicDo (bpmn-modeler.production.min.js:27)
    at Th._internalExecute (bpmn-modeler.production.min.js:27)
    at Th.execute (bpmn-modeler.production.min.js:27)
    at pm.updateProperties (bpmn-modeler.production.min.js:27)


It fails at ElementRegistry#validateId. You’re probably duplicating IDs. I encourage you to simply debug this issue. Make sure to not use the minified distribution for debugging.

Yeah in bpmn diagram when user is trying to update the task id or event id , I want to catch the error and display in pop up rather than in console.

Sometimes user may put the same id for task/event while updating the default id.

So can you explain me in terms of the above case.
How to handle the above case.


What have you tried already to build this feature?

We are using bpmn-js package in Angular 8.

Where we can find the file you mentioned to handle the “element with id Task_1 already added” error.


You should prevent the error in the first place. Make sure to check whether an ID has already been assigned and only set the ID of your element if it hasn’t.

function idAssigned(id, businessObject) {

  // every business object has a reference to the model which has a reference to the ids
  return businessObject.$model.ids.assigned(idValue);

const businessObject = element.businessObject;

if (!idAssigned(id, businessObject)) {
  // change ID