Create a comma-separated list from multi-instance outputs

Dear Experts,

we are using a multi-instance call activity to create users in a system, say 3 of them, user1, user2 and user3. In the subsequent call activity, which is not a multi-instance, we need to enter these 3 users in a single input field, ideally value would be “user1,user2,user3”.

We tried a lot with in- and out parameters and execution listeners at different locations, like end of multi-instance, endEvent of called child, but we were not successful.
Example of execution listener which produced the “best” result so far:

String user = execution.getVariable(“user”);
if (null != user) {
user += “,” + execution.getVariable(“CT_USER”);
}
else {
user = execution.getVariable(“CT_USER”);
}
execution.setVariable(“user”, user);

When attached to the end of the multi-instance call activity, it produces value “user1,user1,user1,user1”, so, 4 identical entries in a comma-separated list.

I think it is something like described here what we need: Multi Instance Variable Aggregation – Flowable Blog, but we are on 6.5 only.

Is there any other elegant solution how to generate the comma-separated list concatenated from all individual output values of the multi-instances?

What about event listeners like multi_instance_activity_completed or variable_update, could they help here?

Thanks for your support!

Regards,
Joachim

Hey @wollschwein,

I would suggest that you use the multi instance variable aggregation. There is an option to provide a custom VariableAggregator for your multi instance variable aggregation. You can implement one named CommaSeparatedVariableAggregator. You could even contribute it to Flowable through a PR :wink:.

Apart from using a custom VariableAggregator, you can even use the current implementation. First create an array node of the values you need and then use a second multi instance sequential execution in which you will do what you are doing in your execution listener right now.

Cheers,
Filip