Getting task Id of a task running in a parallel flow

Dear Camunda community,

I have a case of two tasks being executed in parallel. One sends an email notification to reviewer, another one is an actual reviewer UserTask. I want to pass in email a taskId (to have a link to a Task list web app in email). However, when I run
def taskId = execution.getProcessEngineServices().getTaskService().createTaskQuery().processInstanceId(execution.getProcessInstanceId()).list()

in step 020 in input parameters - I get nothing. So, apparently, Task 010 was not yet created. Both 010 and 020 are set asynchronous after / exclusive

image

What would be a proper way to ensure that another task in a parallel flow already exists to retrieve its id?

Thank you.

Best regards,
Ilya

That isn’t the best approach, you should instead use a task listener on the user task which runs once the task has been assigned that way you’d have access to the task ID and it was also work incases where the task is reassigned. It would look something like this:

1 Like

Hi Niall,

Hope both you and your hawk are doing well. Thank you for your suggestion. I am quite keen to keep “low-code” approach, so the proposed solution is not in line with our architecture. At the moment adding a timer before Notify event works for me. However, I’m looking for a more robust way to synchronise / correlate activities here using signals/messages probably?

image

Best regards,
Ilya

Thanks for asking - my hawk often feels like he deserves more attention on the forum, he’ll be happy to her someone was asking about him :slight_smile:

I don’t think adding a timer is a very good idea though - a much better solution would be to add a transaction boundary before your notify task - you can do that as follows:
EDIT: Please ignore the fact i closed the gateway incorrectly.

This would ensure that the task has been committed to the database (and so has an ID) before the email is sent.

Brilliant! Thanks a million for such an elegant solution!

1 Like