Updating Task#resources in BPMN 2.0 XML


#1

Hi there,
I want to use attributes of the bpmn which are already defined in the bpmn.json-file.
For testing I attached the following new action to the ContextPadProvider (resources attribute to Task):

'resource':{
      group: 'edit',
      className: 'icon-screw-wrench',
      title: 'Set Resource',
      action: {
          click: function(event,element){
             var result=window.prompt('Resource role of '+element.name);
            if(result){
               modeling.updateProperties(element,{'resources':result});
            }
     }
  }
}

If I debug the Task the businessObject got the attribute, but if i export the diagramm to xml the property is not included.

Have i forgotten to register the “new” attribute somewhere?

Greetings
Korbinian


#2

The BPMN meta-model defines Activity#resources as a many property to elements of type ResourceRole. Make sure to put elements of type ResourceRole into the collection and not strings (these are returned from window.prompt(...)).

BPMN types such as ResourceRole can be created using the BpmnFactory:

// creating new resource role
var resourceRole = bpmnFactory.create('bpmn:Performer', { name: 'FooBar' });

// updating task
modeling.updateProperties(element, { resources: [ resourceRole ] });

#3

Great, Thanks!

And how do I achieve to add bpmn:PartnerRole with a Participant as ‘participantRef’-attribute. With the following code it is not rendered to xml.

var bo=element.businessObject;
var resourceRole=elementFactory._bpmnFactory.create('bpmn:PartnerRole',{'name': "AppEnsemble",'participantRef':bo});

I also tried to give them a shape via:

var PartnerRole=elementFactory._bpmnFactory.create('bpmn:PartnerRole',{'name': "AppEnsemble"});
var PartnerRoleShape=elementFactory.createShape({businessObject:PartnerRole});
modeling.updateProperties(PartnerRole,{'participantRef':bo});

Where is my mistake?

Thanks again!
Korbinian


#4

You need to properly add the bpmn:PartnerRole element to the underlying BPMN 2.0 document.

Please share the full code snippet you are using so that I get a better idea of what you might do wrong.


#5

OK, here is my full snippet (in the ContextPadProvider)

if(is(bpmnElement,'bpmn:Participant')){

    assign(actions, {
        'partnerRole': {
            group: 'edit',
            className: 'icon-flag',
            title: 'Mark as AppEnsemble',
            action: {
                click: function(event,element){
                    var bo=element.businessObject, inputtext;
                    var result=window.confirm('Do you really like to mark the Participant ('+ bo.id+') as AppEnsemble?');
                    if(result){
                        var PartnerRole = {
                            type: 'bpmn:PartnerRole',
                            businessObject: elementFactory._bpmnFactory.create('bpmn:PartnerRole',{'name': "AppEnsemble"})
                        };
                        modeling.updateProperties(PartnerRole,{'participantRef':bo});
                    }
                }
            }
        }
    });

}

When I debug the code I can see, that the PartnerRole is initialized correctly, but it seems not to be added to the BPMN document.


#6

In your current case I see a number of issues:

  • Invisible BPMN elements do not need to be wrapped in diagram elements
  • The partnerRole element is a bpmn:RootElement and has to be added to the Definitions#rootElements collection to be contained within the BPMN document

The following code snippet should do the job:

var partnerRole = bpmnFactory.create('bpmn:PartnerRole', { name: 'AppEnsemble', participantRef: [ participant ] });

// unwrap Participant -> Collaboration -> Definitions
var definitions = participant.$parent.$parent; 

// wire partnerRole with BPMN document (via Definitions)
definitions.get('rootElements').push(partnerRole);

Note that I do not use modeling.updateProperties(...) because definitions is not a diagram element. This is something we could support in the future. If you would like to make the assignment undoable, read this thread.