Can we execute external task on task lifecycle events

Is it possible to configure an external nodejs microservice to run on any lifecycle events?

Not right now - although @Nele did create a quite interesting workaround for this that she might be able to share with you.

Well in one Project where we needed a Listener as an external Taks worker, we used a Scrip in the task listener to basically set a variable. Then we used in BPMN an event subprocess with a non interrupting conditional event that was triggered once the variable was set. This was followed by a service task which we implemented as external worker and was the main listener… something similar like this example.bpmn (4.2 KB)

Of course your model might get a little bit more unstructured… Depending on how many different Listeners you need…

2 Likes

@Niall @Nele Thanks! This makes sense :smiley:

Hi @Nele - I had attended your unconference session yesterday! :smiley:

So I was trying to model my use case where I need to assign the task to the user in my application, as well as to send a notification for the user. So what I understand is that I need to have a reference to the task ID so that the user can complete the task on my app.

image

When the execution reaches this step, I need to trigger an external task. For that I have assigned the variable as below,

I have modeled the sub process as below,
image

image

What is happening is that the variable gets set correctly, but the sub process is not executing. So I tried opening cockpit and changed this userTaskStart variable from true to false, and then again to true. When that happened it sent execution to the sub process, and it exited!

Is there something I am missing?

  1. I need the sub process to execute when the task is created - this will run business logic to sync task id to application
  2. I need the execution to resume at the task

Hey @johnjacobkenny
the last time we used such a pattern was not on an usertask. So I rebuild the case and I get the same problem. I don’t think that this behavior is intended… at least it confuses me… I’ll try to get more insights and let you know if I can get more information… or we both wait if someone shows up, who can explain it here ^^

1 Like

Hi,
I cannot explain at the moment why it is not working at the task create event, but if you use this expression on a EventListener ( event-type: start) then it works as expected.

1 Like

@McAlm thanks for the input. I did not exactly understand where to make the change, I have tried each of the following and it is not working,

image

I am getting errors using the REST API for the last two settings.

Hi @johnjacobkenny, please have a look at this example: UserTaskTriggersEventSubProcess.bpmn (4.4 KB)

Best, Stefan

1 Like

@McAlm yes that worked for me and I am able to access the sub process task details in my nodejs worker.

Am I right in thinking that I should make a REST call in my worker to engine-rest/task?processInstanceId=... to get the original user task details, and perform my application fuctionality?

Yes. You can use whether a GET call

or a POST request (which is slightly more powerful)

to filter for the task.

Be aware that you have to complete not only the user task but also the external task, otherwise your process instance will not finish.

1 Like

You can even simplify it more by adding a create listener that adds the task id to the process variables. This way your worker can filter directly for that specific task. See this example:
UserTaskTriggersEventSubProcess.bpmn (4.5 KB)

1 Like


Hi @McAlm ,

I am not able to import your attached BMPN, I am getting warning, how the parent process linked with subprocess. Could you please give me insight on the same. Since I have use case whenever user task created I want to capture the user task details by calling REST call or java delegate in Camunda. So that i can internally call publish event java delegate?

Hi @matab.b : You can simply use a TaskListener to execute addition business logic. Please have a look here: Delegation Code | docs.camunda.org

P.S.: The warning can be removed by changing camunda:variableEvent to camunda:variableEvents within the xml.