Set default values for the newly created node

I would like to implement the ability to set default values for my nodes at creation time.

Is there some way to do this at node creation time?

What is your context? Which modeling tool do you use, how do you create new nodes?

If I understand correctly, then the initialization of my modeler looks like this.

 bpmnViewerRef.current = new Modeler({
            container,
            keyboard: {
                bindTo: document,
            },
            moddleExtensions: {
                custom: customModelExtension,
            },
            additionalModules: [translation, customModele, { autoPlaceSelectionBehavior: ['value', null] }],
        })

node props some think like this:

"name": "NodeProps",
            "extends": ["bpmn:Task", "bpmn:CallActivity"],
            "properties": [
                {
                    "name": "inputsNumber",
                    "isAttr": true,
                    "type": "String"
                },

                {
                    "name": "modelType",
                    "isAttr": true,
                    "type": "String"
                },
type or paste code here

Node creation is performed using the standard bpmn interface, from the palette on the left side of the screen or from the context menu (which is next to the selected node)

I’m using a custom render node, but there are no significant deviations from what bpmn provides out of the box

The behavior I want to achieve.

for each node of type bpmn:Task I have a set of fields described in the model file, let’s say:
Name
Date of Birth
Work days

The behavior I want to achieve.

for each node of type bpmn:Task I have a set of fields described in the model file, let’s say:
Name
Date of Birth
Work days

I would like that every time the user creates a new node, the field “Working days” is filled with a default value (for example, data previously received from the server) and the user does not have to enter them with his hands, while the fields Name and Date of birth remain empty .
In my case, it is important that the data must be written to the node object, since based on this data, I draw information on the node (for example, for every Mon-Fri), that is, by default, the data must be written to the newly created node, not just a form in the property panel (which appears when the user selects any of the nodes)

Please tell me the best way to do this

addition, I also have a need to set the node label by default at the time of creation, according to the pattern
label N, where N is the ordinal number of the node, I need this behavior to exclude unnamed nodes in the script

From what it looks like you want to replace/subclass the elementFactory.

It is used across the tool to create new elements. Alternatively you can explicitly hook into element creation (by a user) through a command handler:

// apply default element templates on shape creation
eventBus.on([ 'commandStack.shape.create.postExecuted' ], function(event) {
  const {
    context: {
      hints = {},
      shape
    }
  } = event;

  if (hints.createElementsBehavior !== false && is(shape, 'myExtension:NodeProps')) {
    // apply additional change, i.e. via `modeling.updateModdleProperties`
  }
});

I don’t understand where exactly should I make these changes to get the desired behavior

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.