Add in the BPMN XML a custom attribut in the bpmn:task attribut

Hello Team,

I need to customize the BPMN Xml in order to add a custom attribut called RankOrder = “1” in the bpmn:task attributes which will be set programmatically,
Would you please help me?

Thanks in advance.

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">
  <bpmn:process id="Process_1" isExecutable="false">
    <bpmn:startEvent id="StartEvent_1" name="Open">
      <bpmn:outgoing>SequenceFlow_1bc95bk</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:task id="Task_0ne4plj" name="In Progress"   RankOrder = "1">
      <bpmn:incoming>SequenceFlow_1bc95bk</bpmn:incoming>
      <bpmn:incoming>SequenceFlow_0ueolp0</bpmn:incoming>
      <bpmn:incoming>SequenceFlow_1bs32ij</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_1r4mdx2</bpmn:outgoing>
      <bpmn:outgoing>SequenceFlow_0navib1</bpmn:outgoing>
      </bpmn:task>  <bpmn:task id="Task_17yscmr" name="Approved" RankOrder = "2">
      <bpmn:incoming>SequenceFlow_084pksv</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_0ol0tj0</bpmn:outgoing>
</bpmn:task>

Hi Dhaker,

You have to use a custom descriptor, e.g.

./lib/descriptor/customDescriptor.json

{
  "name": "customDescriptor",
  "uri": "http://customDescriptor",
  "prefix": "custdesc",
  "xml": {
    "tagAlias": "lowerCase"
  },
  "associations": [],
  "types": [
    {
      "name": "RankOrder",
      "extends": [ "bpmn:Task" ],
      "properties": [
        {
          "name": "rankorder",
          "isAttr": true,
          "type": "String"
        }
      ]
    }
  ]
}

this will recognize the attribute

<bpmn:task id="Task_0ne4plj" name="In Progress" custdesc:rankorder="1">

you have to include the moddle descriptor as

./lib/Viewer.js

 var customDescriptor = require('./descriptor/customDescriptor');
 var viewer = new Viewer({
    container: '#divcontainer',
    moddleExtensions: {
      customDescriptor: customDescriptor
    }
  });
2 Likes

Hello David,

Thank you so much you save my day.
Q1: does the ./lib/descriptor/customDescriptor.json file will override the actual one in .//bpmn-moddle/blob/master/resources/bpmn/json/bpmn.json?

other request please, which i dropped in the [Camunda Forum] (https://forum.camunda.org/t/connect-modeler-elements-programmatically/2152/5)

Is there a way to connect task via javascript code without using the arrow connection shapes:
In my case i have a generic task that will be dropped in the diagram then all other tasks will connect to it implictly without using the sequence/Message fow action,

Any clues :wink:

Thank you again.
Dhaker