Add extension elements with any type (i.e. camunda:inputOutput)


#1

Hi,

I would like to generate following model:

<bpmn2:userTask>
  <extensionElements>
    <camunda:inputOutput>
      <camunda:inputParameter name="assigneeEntity">user</camunda:inputParameter>
    </camunda:inputOutput>
  </extensionElements>    
</bpmn2:userTask>

Here is what I am doing:

var userTaskMoodle = ...;
var extensionElementsMoodle = moddle.create('bpmn:ExtensionElements');
var inputOutputMoodle = moddle.createAny('camunda:inputOutput', 'http://activiti.org/bpmn');
var inputParameterMoodle = moddle.createAny('camunda:inputOutput', 'http://activiti.org/bpmn', {
  name: 'assigneeEntity'
});
inputParameterMoodle.body = 'user';
inputOutputMoodle['camunda:inputParameter'] = inputParameterMoodle;
extensionElementsMoodle['camunda:inputOutput'] = inputOutputMoodle;
userTaskMoodle.businessObject['extensionElements'] = extensionElementsMoodle;

And this is the result:

<bpmn:userTask>
  <bpmn:extensionElements />
</bpmn:userTask>

What am I doing wrong?


#2

bpmn:ExtensionElements contains individual members in the value property.

Refer to the meta-model descriptor for details.

So in order to properly add it into the BPMN 2.0 document, you need to add the camunda:inputOutput like this:

// use ModdleElement#get('propertyName')
// to safely access a collection property

extensionElementsModdle.get('values').push(inputOutputModdle);

#3

Hi nikku,

How am I supposed to put camunda:inputParameter moddle under camunda:inputOutput;
This is not working:


inputOutputMoodle.get('inputParameters').push(inputParameterMoodle);

Is this because I created these custom moddles with createAny() method?


#4

Inside AnyTypes, i.e. elements create with moddle.createAny(...) the two special properties $body and $children allow you to wire child elements.

What it boils down to is something like this:

var inputParameter = moddle.createAny('camunda:inputParameter', camundaNs, {
  name: 'assigneeEntity',
  $body: 'user'
});

var inputOutput = moddle.createAny('camunda:inputOutput', camundaNs, {
  $children: [
    inputParameter
  ]
});

...

I added a test case that should illustrate the details.


#5

Hi nikku,
may you can help me understanding this? I want to do the same thing as the topic writer…
I do it your way and it works very fine.

But here is my problem. I want to read the input/output parameters after setting them.

var elementRegistry = modeler.get('elementRegistry');
var elementRegistryEntry = elementRegistry.get(pElement.element.id);
var elementRegistryEntryBO = elementRegistryEntry.businessObject;

elementRegistryEntryBO.extensionElements.values[1].$children

all fine…
but if I save my xml and load it new, $children is undefined. then i need to access this way:

elementRegistryEntryBO.extensionElements.values[1].values

So first I can access them via $children and after reloading the xml i need to do it via values…

That causes another problem. I additional save an attribute “type” to my inputParameter. If I reloaded my existing xml into the modeler, the “type” is lost.

<camunda:inputParameter type="ABC" name="ANYNAME">ANYNAMEVALUE</camunda:inputParameter>

its very annoying to have always a different structure of my businessobject, just cause i recently added my parameters or loaded an xml where i added the parameters before…

Thanks for your help!


#6

The $children property is exposed for generic elements for which bpmn-js does not know the internal structure.

The fact that you don’t have $children but rather actual typed elements is due to the fact that you made bpmn-js aware of it (most likely by including camunda-bpmn-moddle). In that case you must not create an AnyType but rather the camunda:InputOutput element directly:

var inputOutput = moddle.create('camunda:InputOutput', { ... });

// use similar to any type
// recognize that it has actual instance properties

And by the way: Please do not necrobump old topics. Instead link to this thread from new topic.


#7