I want to get the swimlane an activity belongs to using the Camunda API. How can I do so?
Thanks for your help in advance!
Greetz
Alex
<process id="invoice" name="invoice receipt" isExecutable="true">
<laneSet id="laneSet_5">
<lane id="Approver" name="Approver">
<flowNodeRef>approveInvoice</flowNodeRef>
<flowNodeRef>invoice_approved</flowNodeRef>
</lane>
<lane id="teamAssistant" name="Team Assistant">
<flowNodeRef>reviewInvoice</flowNodeRef>
<flowNodeRef>reviewSuccessful_gw</flowNodeRef>
<flowNodeRef>assignApprover</flowNodeRef>
<flowNodeRef>StartEvent_1</flowNodeRef>
<flowNodeRef>invoiceNotProcessed</flowNodeRef>
</lane>
<lane id="Accountant" name="Accountant">
<flowNodeRef>prepareBankTransfer</flowNodeRef>
<flowNodeRef>invoiceProcessed</flowNodeRef>
<flowNodeRef>ServiceTask_1</flowNodeRef>
</lane>
</laneSet>
// EITHER (1) service API
BpmnModelInstance model = repositoryService.getBpmnModelInstance("..."); // OR (2) inside a JavaDelegate / TaskListener ... (while executing the process)
BpmnModelInstance model = delegateExecuton.getBpmnModelInstance(); // find all lanesets within the model
Collection<LaneSet> laneSets = model.getModelElementsByType(LaneSet.class);
for (LaneSet laneSet : laneSets) {
//iterate the lanes
Collection<Lane> lanes = laneSet.getLanes();
for (Lane lane : lanes) {
// check the flow nodes
Collection<FlowNode> flowNodeRefs = lane.getFlowNodeRefs();
for (FlowNode flowNode : flowNodeRefs) {
// check the id. (note that you can do the check based on aly attribute (also from custom namespace) or child element
if ("prepareBankTransfer".equals(flowNode.getId())) {
// found the lane!
}
}
}
}
Hi Daniel!
Thanks for your answer and that's exactly what I need.
But I have a problem with your code.
The LaneSet.class can't be used for the getModelElementsByType method. I get the following exception:
The method getModelElementsByType(ModelElementType) in the type ModelInstance is not applicable for the arguments (Class<LaneSet>)
I am using Camunda 7.1-Final.
Thanks in advance!