@zambrovski here is a simple solution that adds the custom message based on a Extension property on the task:
BpmnModelInstance addMessages(BpmnModelInstance modelInstance){
modelInstance.getModelElementsByType(ReceiveTask.class).each { receiveTask ->
CamundaProperties properties = receiveTask.getExtensionElements().getElementsQuery().filterByType(CamundaProperties.class).singleResult()
Collection<CamundaProperty> messageDetails = properties.getCamundaProperties().findAll { property ->
property.getCamundaName() == 'MessageName'
}
if (!messageDetails.first().getCamundaValue().isEmpty()){
receiveTask.builder().message(messageDetails.first().getCamundaValue()).done()
} else {
throw new Exception("Cannot add message to element: ${it.getId()} because MessageName extension property value is not set")
}
}
return modelInstance
}
and then setting up the builder with something like:
...
BpmnModelInstance instance = Bpmn.readModelFromStream(resourceStream('bpmn/addMessage.bpmn'))
builder.addModelInstance('addMessage.bpmn', addMessages(instance))
...
its just setup for Receive Task, but you can easily extend / apply the same logic in kotlin and for Throw Events.
inside of the BPMN:
before deployment:
and the result after running the above code: