Find next possible task using rest API

Give a task_id, how can I find out what are the possible future tasks using REST API?

Additionally is it possible to find the future task over REST API by passing possible outcomes of the current task. For eg: If following the current task taskX, there is a gateway that has two paths with condition “#{a}” that leads to taskA and condition “#{not a}” that leads to task B. Is there a way I can ask flowable what would be the next task for taskX if the value for a=True/False?

To my knowledge, Flowable does not have a simple way to do this. You could use the REST API to download the BPMN and parse the XML.

1 Like

@alexp0205 as you can imagine the expressions on the conditions can be quite complex. Evaluating them in advance to figure out potential paths is not easy at all.

Flowable uses JUEL for the expressions and evaluates them when the current task is completed to continue the engine execution.

May I ask you to explain why you want to compute the future task? Which problem are you trying to solve?

1 Like

@filiphr My use case is that I have a user task followed by an exclusive gateway with two paths to two different tasks. On our website, before a customer does an action that internally mark this user task as complete, I want to show a message to the user that if you do this action, the next task will be X - a way to confirm that the user knows what is going to happen next.

What you could do is get the BpmnModel from the repositoryService and inspect what follows after the user task. If there is an exclusive gw with expressions, you’d need to resolve them yourself and see what path will be taken before actually completing the task.

1 Like

Yes, We have implemeted same way as said above by ‘joram’ and it is working fine.

1 Like

Rather than handling expressions, http tasks manually, I was thinking of the following approach.

Process instance - PC1
Current Task - T1
Say we want to find the next task of if T1 completes with a given set a values. I will
(1) Create a copy of the process instance PC1 as PC2 with same state, variables etc.
(2) Complete the corresponding task(T1) in PC2.
(3) Observe what happened in PC2
(4) Delete PC2.

Do you see any challenges with this approach?

That’s possible of course, but probably quite a bit of work to get right (e.g. what about service tasks with side-effects?). Note that you also would need to delete history.

1 Like

Thanks for that. We are thinking to add one variable that can be used to differentiate between normal process_instances and duplicates created for this purpose.

In our backend, we will have to handle APIs called from HttpTasks such that if it has this variable, don’t do any updates, instead just return back a list of changes that would happen without actually doing it. It is relatively easy for us as there are just 2 backend API’s that are used from Flowable.

It is not a generic solution, but I think it would solve our problem.

Would you be able to provide a query example that returns the next task by inspecting the model returned by repositoryService ? thanks in advance.

Since I’m trying to find the next task from a service tasks, this is doing the job for me:

ServiceTask currentFlowElement = (ServiceTask) execution.getCurrentFlowElement();
String nextTaskId = currentFlowElement.getOutgoingFlows().get(0).getTargetRef();

1 Like