Save persistent information on reliable "Root"-Element

Hello there.

I’m working on a software, which adds a configuration-layer to the modeler. The software works, but I’m facing one last issue I’ve found no “beautiful” approach for.

Small introduction to the project-setting - We’ve got:

  • a set of global variables and their values per diagram
  • Connections, which have to be originated from as configurable marked Gateways
    • for these Connections, rules, which depend on the globally defined variables, can be defined for; if the rules are not fulfilled, the subtree behind the connection (and the connection itself) are deactived

The global variables are persisted as stringified json in the “configuration”-attribute of the Process-Element (= Root in standard-cases), which I suspected to be always the Root-Element. The problem is, when I add a lane to the diagram, the Process-Element as Root is replaced with a Collaboration-Element.

In the current state, the global variables are not accessible anymore when creating a lane (because I relied on the assumption, the Root-Element would always stay the same; I’m accessing it with modeler.get('canvas').getRootElement()). What I need is an element, which I can rely on the whole lifecycle of the diagram-processing to be the same.

My current approach - if you don’t have a better idea - is to define the global variables in the Definitions-Element. I’ve found no setter-access to this Element so far, except when exporting an XML from the modeler (I’d have to export to XML and re-import the diagram every time, my global variables are updated, which is no ideal solution). Do I have the ability to set custom attributes to the Definition-Element programmatically? Or do you have a better idea where to store the global variables?

I hope I have made myself clear. Thanks in advance!

Hi @ClemensR,

one approach would be to use extensionElements to store additional information inside the definitions

 var moddle = modeler.get('moddle'),
     definitions = modeler.getDefinitions(),
     extensionElements = moddle.create('bpmn:ExtensionElements');
    
extensionElements.$parent = definitions;
extensionElements.values = [ /** fill with your extension elements **/ ];

definitions.extensionElements = extensionElements;

Another way would be to simply extend the model giving Definitons custom attributes (as you maybe already did with your configuration attribute).

2 Likes

Thank you very much. getDefinitions() gave me the hint, where to set them (they aren’t settable via elementRegistry/updateProperties). I’m doing it with modeler.getDefinitions().set('configuration', JSON.stringify(variables)) now.