Shapes with default named

Hi Guys,
Can I set default name for each and every shape’s?. When I drag and drop any shapes it should come with default name. If anyone knows, Please give some ideas.

Hey,

It’s possible to achieve that, however why would you want to have such functionality? The IDs of shapes should be unique so it’s best not to have default IDs for shapes.

Hi Oguzeroglu,
Thanks for the reply, Actually I’m using bpmlint validation, When I drag any shapes its show some warning so that’s look like disappointing. It would be better with default name.

Ah I see, I’m sorry I thought you meant shape IDs.

You can implement a custom command interceptor for that. Here’s an example: https://codesandbox.io/s/gracious-lamport-vw8tq?file=/src/DefaultNameBehavior.js

In this example the class DefaultNameBehavior takes care of setting default names to the business objects of recently created shapes. We then inject this module to bpmn-js as an additionalModule inside index.js.

Good luck!

Hi Oguzeroglu,
Thanks for the help. I can use to set default value for each and every shape’s.

Hi Oguzeroglu,
The default value has been added, but not visible. It shows when I double click on the label. Is any idea?
And I apply default value for shape append its not working can you help me to solve this issue

You’re changing the name property after the element already has been created. If you want to create elements with a default name, assign it before creating the element.

Furthermore, you’re changing the name in the wrong way. As you’ve observed the changes will not be reflected in the diagram. They also won’t be revertable through CMD+Z. To update the property of an existing element use modeling#updateProperties.

I’ve adjusted your example to demonstrate both ways: https://codesandbox.io/s/default-name-pre-and-post-mii8p

1 Like

Hi Philip,
Thanks for the detailed explanation. :slightly_smiling_face: