Get all possible flows from a task


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());
        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?


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.


Hi Leo,

An example how to get outgoing flows:



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">

    <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} ]]>
    <sequenceFlow id="approved" sourceRef="pointOfDecision" targetRef="task3">
        <conditionExpression xsi:type="tFormalExpression">
            <![CDATA[ ${approved} ]]>

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

How can I get it?



May be you will find it useful