Input/Output variables containing task information

Hello,

I am modeling a system that creates events to an external service. Sometimes when a new task is fired, I want to inform the external process that the previous task needs to be canceled.
Imagine I fired task A and after some time that task expires and Task B must be done instead. When my External Task worker gets the event for task B, The worker most check if Task A must be canceled before staring task B.

My question is How can I model something like that? I am trying to use the Output of task A to provide the instance Id of itself, so when the worker gets the task B event, it will be able to check if the tasks that need to be canceled, and process accordingly.

The problem I have is that I don’t know how to pass the task instance id in the Output variable. Is that possible, I have tried several ways with no success.

Is there any other way to get the desired behavior?

Thank you

Elkin

I think I figure it out. this is what I did.
In the definition of task A, I created and output variable “cancel” with the following value:
${execution.getActivityInstanceId()}.

Then during the processing of task B I check if the variable “cancel” exisit and if so, I will get the task instance ID of A. then I can fire my process to cancel that activity in my application. Once that is done, I can continue firing up the new task B.
The documentation on this feature can be found at: https://docs.camunda.org/manual/7.4/user-guide/process-engine/expression-language/#internal-context-variables

I tried to use the following expression ${task.getInstanceId()} but it did not work. telling me that the task did not exist… probably because when calculating the expression, the task was already destroyed… . Using the environment variable instead could be better as it will always be present.

Elkin