Add default text to bpmn element when dragging it into the diagram


#1

Hi Team,

I would like to add default text in bpmn element when dragging it into the diagram?
please any hints to do that.

Thanks and best Regards,


#2

what is the use case? Do all/most of your elements have the same prefix? Normally the bpmn-text is individual on a high degree


#3

I need when dragging an element will take default name after dragging it into the diagram.


#4

I did something similar: I added some default variable value to an element when it was created.

This module should do the trick:

const BpmnElementFactory = require('bpmn-js/lib/features/modeling/ElementFactory');
const inherits = require('inherits');
const ModelUtil = require('bpmn-js/lib/util/ModelUtil');
const getBusinessObject = ModelUtil.getBusinessObject;
const is = ModelUtil.is;

function ElementFactory(bpmnFactory, moddle, translate) {
    BpmnElementFactory.call(this, bpmnFactory, moddle, translate);
}

inherits(ElementFactory, BpmnElementFactory);

ElementFactory.$inject = [
    'bpmnFactory',
    'moddle',
    'translate',
];

module.exports = ElementFactory;

// Hook into creation process
ElementFactory.prototype.create = function(elementType, attrs) {
    let element = BpmnElementFactory.prototype.create.call(this, elementType, attrs);

    // Only set the name if the element is a task, subprocess or call activity
    if (is(element, 'bpmn:Activity')) {
        getBusinessObject(element).set('bpmn:name', 'This is default text');
    }

    return element;
}

This module must be passend in an object as additional module to the modeler on start-up:

{
    __init__: [ 'elementFactory', ],
    elementFactory: [ 'type', require(/* PATH TO FILE */), ],
};