Temporary custom property

I would like to ask that what is the proper way to add a new custom property temporarily to an existing element (eg.: bpmn:ServiceTask, bpmn:CallActivity)?

I do not want to persist it to the XML and I do not want to add it to modeler._definitions. Only needed for storing some temporary data and calculations.

I tried to add it to:

  • the businessObject attributes:
businessObject.$attrs['customProperty'] = value;   // has been added to the **XML**
  • directly to the businessObject:
businessObject['customProperty']  = value; // has been added to the **modeler._definitions**

Hi @kollerdroid, welcome!

Can you explain your use case a little more in detail? It’s hard to help you without knowing the context.

Hi Niklas, sure.

We store many parameters/data in a relational database connected with an element through its id property.
This values used for eg. calculating some values dynamically or just showing on the diagram.

I load this values on ‘shape.added’ (in case of new diagram/elements) and ‘diagram.loaded’ events (in case of opening an existing diagram).

If this values could be accessible from its businessObject (or something like that) would be very practical.

For this purpose I could imagine a free to use data (eg. an extensionElements like object) property next to id, type, businessObject etc… which is not persisted to the XML.

Thanks for your explanations, it makes it much more clear to me.

One important thing we have to understand: the businessObject is a JS object representation of the XML, that’s what the model is supposed to do when it’s being built. I would personally not storing any additional data inside.

However, we use shapes as our own data structure which also includes those business objects. Inside shapes you are free to add additional properties, as demonstrated in this CodeSandbox.

All that saying, this could be dangerous as well because you are hooking into internal data structures. Personally, I’d go with a separated data layer and maintain this there, in a dedicated manner. E.g. a custom service. Depends on what you want to achieve.

Clear. Thank You Niklas!