As I have understood, when using the bpmn-js modeler, the events contain elements that among other things, refer to an underlying businessObThis text will be hiddenject structure. Yet this isn’t intended to be interacted with directly, but through the modeler. Changing root properties works, but how about categories of properties? Specifically, in a ‘bpmn:SequenceFlow’ element, I would like to give it a ‘conditionExpression’ and set the ‘conditionExpression:body’ property programatically. How would I go about doing this?
This appears to fail due to conditionExpression being undefined:
var modeling = bpmnModeler.get('modeling');
bpmnModeler.on('selection.changed',e => {
if (e.newSelection && e.newSelection.length === 1) {
var element = e.newSelection[0];
if (element.businessObject.$type === 'bpmn:SequenceFlow') {
modeling.updateProperties(element, {
'conditionExpression:type': 'bpmn:FormalExpression'
});
}
}
});
Preferably I would want to check what the source element is also, but that’s a different question
There’s really not much more to it other than this, but I made a codesandbox anyway:
The only issue is I can’t set the conditionExpression:body property because there is no conditionExpression. With the properties panel, I can do it by setting the condition type under details. That is the procedure I am looking to replicate
I know this is an old topic but since I have had the same thing to deal with and luckily I have found a solution I want to share it for the people who might be struggling with the same problem.
First of all I have a function in which inside I check the element clicked by the user:
After getting the element clicked and making a couple of checks I do an if/else to see if the element clicked already has values and if so I update the values if not I set new values both of them using Angular Reactive Forms:
/**
* Function to set condition flow values
* @param conditionFlowValues
*/
setConditionFlowValues(conditionFlowValues: any) {
const modeling = this.bpmnModeler.get('modeling');
const moddle = this.bpmnModeler.get('moddle');
// Ensure selected element exists and is a sequence flow
if (this.selectedElement && this.selectedElement.businessObject.$type === 'bpmn:SequenceFlow') {
// Check if conditionExpression is already set
if (!this.selectedElement.businessObject.conditionExpression) {
const conditionExpression = moddle.create('bpmn:FormalExpression', {
body: conditionFlowValues
});
// Assign the newly created conditionExpression to the sequence flow
modeling.updateProperties(this.selectedElement, {
conditionExpression: conditionExpression
});
} else {
// If the conditionExpression already exists, update the body with form value
this.selectedElement.businessObject.conditionExpression.body =
conditionFlowValues';
// Update the modeler with the new conditionExpression value
modeling.updateProperties(this.selectedElement, {
conditionExpression: this.selectedElement.businessObject.conditionExpression
});
}
}
// Reset form and close modal
this.conditionFlowForm.reset();
this.showConditionFlowModal = false;
}
Of course my use case is for a sequence flow element but I think this approach is going to work for all the elements and also you might need to do fewer check on the if statements.