Compensation task for multi-instance service task Java implementation

139 views
Skip to first unread message

Thomas Schlagbauer

unread,
Sep 23, 2014, 4:52:31 AM9/23/14
to camunda-...@googlegroups.com

Hi guys,

 

I have problems with the implementation of the Java Delegate for the following scenario. The attached process excerpt shows a multi-instance task which is accompanied by a corresponding compensation task.

Now the execution of the compensation task works fine: It executes that often, how often the multi-instance task succeeded. (say, we have 10 interations for the multi-instance task, and it fails at the 4th iteration, then the compensation task executes 3 times.

 

The problem:

In the delegate implementation of the compensation task, there is no connection to the correlating instance of the multi-instance task.


When I try to get one  of the following process variables, they are all NULL:

  • The “Element Variable” defined in multi-instance task
  • execution.getVariable("nrOfInstances")
  • execution.getVariable("nrOfActiveInstances")
  • execution.getVariable("nrOfCompletedInstances")
  • execution.getVariable("loopCounter")

 

My first thinking was to iterate over the original collection (e.g. 10 items) and pick out the relevant items by index. But there is no access to the “loopCounter” variable..

 

Thanks in advance.

Thomas

 


Inline image 1

Daniel Meyer

unread,
Sep 30, 2014, 3:56:06 AM9/30/14
to camunda-...@googlegroups.com, thomas.sc...@gmail.com
Hi Thomas,

sorry for the late answer.

maybe you could wrap the service task in an embedded subprocess and have the embedded subprocess iterate over the collection?
You should then have the variable locally available.

Cheers,
Daniel


thomas.sc...@gmail.com

unread,
Oct 1, 2014, 2:33:30 AM10/1/14
to camunda-...@googlegroups.com, thomas.sc...@gmail.com
Thanks Daniel for the answer. May be a good idea to model the process the way you describe.
For now, I found a workaround for my problem: For each iteration in the service task, I add the id of the started instance to a list and store it as process variable. Later, in the compensation task I have the 'ids of the started instances' available and can just call a compensation service for them.
Reply all
Reply to author
Forward
0 new messages