Creating BPMN elements with pre-defined custom attributes


#1

Continuing the discussion from this topic:

You cannot easily do this right now.

But is it possible? Even if it isn’t an easy thing to do.
I need to have a predefined class in service task - every service task will have that class, so would be stupid to make the user select/insert a class value in properties panel.

I’ve defined the properties panel to show a default value but that won’t be written to the xml unless the user modifies it.

I need this for that use case and for others like a selectbox:
Imagine the select box has 2 values (A and B) and A is the one selected by default (i dont have an empty value therefore A will be shown as selected) but that won’t pass to the xml unless the user selects B and then selects A. What it is meant to do is to write A in the xml, even without any input from the user.

Is that possible?

In my descriptor (i’ve made one for activiti) i have this:

[...]
{
      "name": "AnotherTask",
      "extends": [
          "bpmn:ServiceTask"
        ],
      "properties": [
        {
          "name": "test",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "class",
          "isAttr": true,
          "type": "String",
          "default":"com.company.bpmn.AnotherTask"
        }
      ]
    }
[...]

Then i have a file named AnotherTaskProp.js, in which i defined the the entryfactories for these properties:

function ensureFormKeyAndDataSupported(element) {
    return is(element, 'bpmn:ServiceTask');
}
module.exports = function(group, element, translate) {
    if(!ensureFormKeyAndDataSupported(element)){
        return;
    }

    console.log(getBusinessObject(element));
    group.entries.push(entryFactory.selectBox({
        id: 'test-type',
        label: translate('Test Type'),
        modelProperty: 'testName',
        get: function(element, node) {
            var bo = getBusinessObject(element);
            return {
                'testName' : bo.get('activiti:test') || 'A'
            };
        },
        set: function(element, values, node) {
            var bo = getBusinessObject(element);
            var testName = values.testName;

            return cmdHelper.updateBusinessObject(element, bo, { 'activiti:test': testName});
        },
        selectOptions: [{ name: 'A', value: 'A' }, { name: 'B', value: 'B' }]
    }));


    group.entries.push(entryFactory.textField({
        id: 'class-task',
        label: translate('Class'),
        modelProperty: 'class',
        set: function(element, values, node) {
            var bo = getBusinessObject(element);
            var prop = {};
            prop["activiti:class"] = values.class;

            return cmdHelper.updateBusinessObject(element, bo, prop);
        },
        get: function(element) {
            var bo = getBusinessObject(element);
            cmdHelper.updateBusinessObject(element, bo, {"activiti:class" : getBusinessObject(element).get('activiti:class') || "com.company.bpmn.AnotherTask"});
            return {'class':getBusinessObject(element).get('activiti:class') || "com.company.bpmn.AnotherTask"};
        }

    }));
};

And the values in the “|| other” or "|| ‘com.company.bpmn.AnotherTask’ ", appear in the properties panel but aren’t passed to the XML and even after hours exploring this i haven’t figured how to do it.


Setting default attribute for elements
#2

A post was merged into an existing topic: Setting default attribute for elements


#3