Get all possible flows from a task

#1

I’m trying to get all possible outgoing transitions from one task.
I have the taskId and I used it in taskService to get the task. This task is defined as a userTask. I was planning to get outgoing flows from that user task, but when I try to cast the task loaded from the taskService I got a classCastException.

Task tarefa = taskService.createTaskQuery().taskId(idTarefa).singleResult();
if (tarefa instanceof UserTask) {
        UserTask tarefaUsuario = (UserTask)tarefa;
        List<SequenciaFluxo> fluxos = new ArrayList<>();
        for(SequenceFlow sf : tarefaUsuario.getOutgoingFlows()){
            SequenciaFluxo fluxo = new SequenciaFluxo(sf.getName(), sf.getConditionExpression());
            fluxos.add(fluxo);
        }
        return fluxos;

if I try to cast to UserTask i got the error:
Cannot cast ‘org.flowable.task.service.impl.persistence.entity.TaskEntityImpl’ to ‘org.flowable.bpmn.model.UserTask’
What is the correct way to get the userTask and then get the outgoing flows?

#2

You need to identify the process definition from the process Instance and then load the process definition XML using BPMNParser. Then you willbe able to get the UserTask and its flows. The one you are accessing is an instance of a process definition and what you are looking for is the actual process definition.

#3

Hi Leo,

An example how to get outgoing flows:

Regards
Martin

#4

Thank you for the awsers.
I got the outgoing flows from bpmModel, but it was not what I was looking for.
I defined a process with a UserTask. I want to know what are all possible paths for the user from this task. With the sugestions I got the outgoing as a sequenceFlow, but what I want is the outgoing from the exclusiveGateway that is connected as the target of the sequenceFlow.

    <userTask id="userTaskExample" flowable:candidateGroups="GROUP1">
    </userTask>

    <sequenceFlow id="linkTaskToGateway" sourceRef="userTaskExample" targetRef="pointOfDecision" />

    <exclusiveGateway id="pointOfDecision" name="Decision from user" />
    <sequenceFlow id="rejected" sourceRef="pointOfDecision" targetRef="task2">
        <conditionExpression xsi:type="tFormalExpression">
            <![CDATA[ ${!approved} ]]>
        </conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="approved" sourceRef="pointOfDecision" targetRef="task3">
        <conditionExpression xsi:type="tFormalExpression">
            <![CDATA[ ${approved} ]]>
        </conditionExpression>
    </sequenceFlow> 

I would like to pass a taskInstanceId from the user task (userTaskExample) and get the sequenceFlows “rejected” and “approved”.

How can I get it?

Thanks

#5

May be you will find it useful

Regards
Martin