Add <flowable:taskListener> to the xml

I want add flowable:taskListener tag to the xml. Like this:

<userTask id="xxxx" name="submit" flowable:formKey="xxx">
    <extensionElements>
      <flowable:taskListener event="create" delegateExpression="${automaticallyCompleteTasksListener}"></flowable:taskListener>
      <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
    </extensionElements>
  </userTask>

But I don’t know how to do, I tried to write it this way:

moddle.create('flowable:taskListener')

But it will report an error: unknown type flowable:taskListener
My English is not very good. Did I clarify my question?
If you can help me, thank you very much

There’s one more thing I don’t understand,<flowable:taskListener> uses namespace bpmn . Why is this not supported

You have to either declare the flowable namespace using a bpmn-moddle extension (an example is the camunda moddle extension) or create your element using moddle.createAny.

What is better for your use case really depends. Do you want to implement a flowable editor based on bpmn.io?

Yes, our xml is generated by Flowable, and I now need to edit and render this xml.

Thank you first of all for your answer.
As you suggested, I tried moddle.createAny :

moddle.createAny('flowable:taskListener', {
        event: 'create',
        delegateExpression: $v('automaticallyCompleteTasksListener'),
      })

But the xml I get looks like this:

<flowable_1:taskListener />

Is there something wrong with my usage? Why does _1 appear?

I seem to understand what you mean, I need to build a moddle dedicated to the flowable namespace, like camunda-bpmn-moddle, right? No one on github seems to have contributed anything like this.

1 Like

flowable_1 in the case is just the prefix. What you have to provide to moddle#createAny is a namespace under which the element resides:

const element = moddle.createAny('foo:Bar', 'http://tata', {
  count: 10
});

During write the utility will try to keep your prefix (if it matches the already specified namespace declaration).

I think there will be similar scenes in the future, So here’s my solution:
First I created a moddle JSON file

// flowable.moddle.json
{
  "name": "Flowable",
  "uri": "http://flowable.org/bpmn",
  "prefix": "flowable",
  "xml": {
    "tagAlias": "lowerCase"
  },
  "associations": [],
  "types": [
    {
      "name": "taskListener",
      "superClass": [ "Element" ],
      "meta": {
        "allowedIn": [
          "bpmn:UserTask"
        ]
      },
      "properties": [
        {
          "name": "expression",
          "isAttr": true,
          "type": "String"
        },
        ... ...
      ]
    }
  ],
  "emumerations": [ ]
}

Then pass it in at instantiation time:

const moddle = new BpmnModdle({
  flowable: FlowableModdle
})
moddle.create('flowable:taskListener', { 
    ... ...
})

It seems to have solved my problem quite well!

1 Like

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