How to compensate per instance for a multi-instance activity

Hi,

When I have a simple process that has a multi instance activity on which I have assigned a collection and an element variable. Then this activity is executed as often as the number of elements in the collection and the element as well as a index is provided as variable per instance.

When compensation is executed for this activity, the compensation activity is invoked as often as the original task. However the context per instance is not provided. I’d expect the index and the element to be available to the compensation activity as they were to the activity that this is attached to.

How can I make sure I am able to apply the compensation activity per instance, for which I’d need the context variable containing the element that the original activity was executed upon?

Regards,
Patrick

Hi Patrick,

when you compensate a multi-instance activity then the compensation handler can access the latest variables of this instance. But I think this works only if you have an embedded subprocess. Please have a look at the docs.

Does this help you?

Best regards,
Philipp

Hi Philipp,
Thanks for your reply. I read the docs and after some trial and error I managed to have a sort of solution.

To summarize:

  • Multi-instance compensation works only for a expanded subprocess;
  • Compensation must be defined at the level of activities in the subprocess;
    Not on the subprocess itself.

Then still the element variable for the multi-instance collection is NOT passed. However, if you copy this value in an activity in the subprocess to a local variable, that local variable will be available in the compensation.

So that’s a way to get this working. Unfortunately it does not work for composition using Call Activities. This non-feature is well documented, but limits the usability of the compensation activities in my opinion. This is a pity as this could be one of the compelling aspects of choosing for a solution like Camunda.
Hopefully, supporting compensation on Call activities as well as maintaining the local variables that refer to the collection element, will be part of a future release of Camunda.

Is this visible somewhere? And if not, how could I add these feature requests?

Kind regards,
Patrick

1 Like

Hi Patrick,

nice to hear that you found a solution :tada:

It’s a known issue that the element variable is not present for compensation (see https://app.camunda.com/jira/browse/CAM-4268).

You can track the current status in your Jira. Feel free to create a new issue for a feature request or bug report.

Best regards,
Philipp

Thanks. Nice to see it is already on your board (for quite some time actually) and that you reported it. I was not aware of this when I posted my question.
Anyway, thanks a lot.

Kind regards,
Patrick