Hello Everyone,
I am trying to add a custom attribute to an existing bpmn element that is bpmn:Task it took me 3 days but still no success can you help me how can I do it
I’m using angular 15 and following is the approach I have used
@ViewChild('canvas') canvas: ElementRef;
modeler: BpmnModeler;
ngAfterViewInit(): void {
this.modeler = new BpmnModeler({
container: this.canvas.nativeElement,
moddleExtensions: {
custom: customDescriptor
}
});
if (this.xml) {
this.modeler.importXML(this.xml);
} else {
this.modeler.createDiagram();
}
const eventBus: any = this.modeler.get('eventBus');
const events = [
'element.dblclick',
];
events.forEach((event) => {
eventBus.on(event, (e) => {
this.selectedActivity = e.element;
if (this.selectedActivity.type == "bpmn:Task") {
this.displayContractObjectForm();
this.visible = true;
}
});
})
}
updateModeler(xml: string) {
this.xml = xml;
this.modeler.importXML(xml);
}
handleObjectChangeActivity(event: ObjectChangeInformation) {
const modeling: Modeling = this.modeler.get('modeling');
const elementRegistry: any = this.modeler.get('elementRegistry');
const taskElement = elementRegistry.get(this.selectedActivity.id);
if (taskElement) {
modeling.updateProperties(taskElement, {
'custom:myCustomAttribute': 'Your Value Here'
});
this.modeler.saveXML({ format: true });
console.log('xml =>', this.xml);
} else {
console.error('Task not found');
}
}
the customDescriptor is as follow
{
“name”: “Custom”,
“uri”: “http://yourcompanyxyzavs.com/schema/bpmn/custom”,
“prefix”: “custom”,
“xml”: {
“tagAlias”: “lowerCase”
},
“types”: [
{
“name”: “ExtTask”,
“extends”: [
“bpmn:Task”
],
“properties”: [
{
“name”: “myCustomAttribute”,
“isAttr”: true,
“type”: “String”
}
]
}
],
“emumerations”: ,
“associations”:
}
I applied many ways but could not get any success
also took help from followign source