How to design a process with a dynamic number of sub process tasks?

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
paiyyavj13
Established Member II

How to design a process with a dynamic number of sub process tasks?

Jump to solution

In the above process, I want the tasks within the Red box to be part of a Sub process- this has to be performed as many times as I select Actor Groups in the "Update Notice Task". 

For Example I may choose a HR group and a Finance Group as Actors, then the above review Tasks needs to create 2 sub processes(each subprocess would have different data depending on the type of Group).

The subsequent Master process( inthe above example "Compliance SignOff")tasks need to wait till both these subprocesses end and then proceed execution.

Please guide....

Regards

1 Solution

Accepted Solutions
gdharley
Intermediate

Re: How to design a process with a dynamic number of sub process tasks?

Jump to solution

Actually loop cardinality isnt the right approach on this occasion.

Assume you have a dynamic list of users you want to assign tasks to.

ArrayList idList = new ArrayList();
Long tenantId = currentUser.getTenantId();

List<User> users = userService.getAllUsers(0,999,tenantId);
for (User u : users) {
idList.add(u.getId());
}

execution.setVariable('assigneeList', idList);

Now, setup the Multi Instance properties as follows:

Collection (Multi Instance) = assigneeList

Multi Instance Type = parallel (or serial, doesnt matter)

Completion Condition = No Value

Cardinality = No Value (not used in this case)

Element Variable - assignee (this takes each element from the list and creates a named variable in the sub process)

Assignment = ${assignee) - if this is a complex type and includes other data, point to the user id element.

Now you will have a dynamic number of instances with dynamic assignment and dynamic data elements based on the ArrayList used to trigger the multi instance.

This is really super powerful stuff, and the Completion Condition can be used to model what are typically complex scenarios such as two eye approval etc.

Cheers,

Greg

8 Replies
gdharley
Intermediate

Re: How to design a process with a dynamic number of sub process tasks?

Jump to solution

This is the perfect situation to use a multi instance called activity. The number of Called Activity instances can be mapped to an array and assignment and mapped data can be pulled from the array as well. 

Cheers,

Greg

paiyyavj13
Established Member II

Re: How to design a process with a dynamic number of sub process tasks?

Jump to solution

Hi Greg,

Thank you for your response....

I have used your inputs and re-designed my process and now it looks like this:

The red marked task is the Call Activity Task, which calls my sub process which I have designed as a separate process.

I have again currently made it work for only one instance of subprocess. i.e.: The sub process is called only once from the master process.

From your comment, I understand that I can store the number of Called Activity instances and mapped data in an Array and use it. 

My query is:

How do I call multiple instances of the Call Activity(subprocesses)? Can I configure the Multi Instance property in the Call Activity Task? or Use some Activiti API?

Appreciate your help.... Thank you...

Regards.

nikmenke
Active Member II

Re: How to design a process with a dynamic number of sub process tasks?

Jump to solution

Hi Paiyyavj13 _,

you can set the loopCardinality with a variable you pass to the process. The loopCardinality says how much instances of the call activity will be created.

<callActivity id="callDeptReviewCallActivity" calledElement="callDeptReview">
  <multiInstanceLoopCharacteristics isSequential="false|true">
    <loopCardinality>${variable}</loopCardinality>    
  </multiInstanceLoopCharacteristics>
</callActivity>

For more information take a look in the user Activiti User Guide at Chapter 8.5.14.

Niklas

gdharley
Intermediate

Re: How to design a process with a dynamic number of sub process tasks?

Jump to solution

Actually loop cardinality isnt the right approach on this occasion.

Assume you have a dynamic list of users you want to assign tasks to.

ArrayList idList = new ArrayList();
Long tenantId = currentUser.getTenantId();

List<User> users = userService.getAllUsers(0,999,tenantId);
for (User u : users) {
idList.add(u.getId());
}

execution.setVariable('assigneeList', idList);

Now, setup the Multi Instance properties as follows:

Collection (Multi Instance) = assigneeList

Multi Instance Type = parallel (or serial, doesnt matter)

Completion Condition = No Value

Cardinality = No Value (not used in this case)

Element Variable - assignee (this takes each element from the list and creates a named variable in the sub process)

Assignment = ${assignee) - if this is a complex type and includes other data, point to the user id element.

Now you will have a dynamic number of instances with dynamic assignment and dynamic data elements based on the ArrayList used to trigger the multi instance.

This is really super powerful stuff, and the Completion Condition can be used to model what are typically complex scenarios such as two eye approval etc.

Cheers,

Greg

paiyyavj13
Established Member II

Re: How to design a process with a dynamic number of sub process tasks?

Jump to solution

Thank you Greg for your post.... It really helped a lot...I had to do some minor changes for group assignment... 

Regards.

gdharley
Intermediate

Re: How to design a process with a dynamic number of sub process tasks?

Jump to solution

Glad to hear it. 

Greg

paiyyavj13
Established Member II

Re: How to design a process with a dynamic number of sub process tasks?

Jump to solution

Hi Greg,

I have a quick question and I did not want to create a separate thread for this query:

I am trying to send some additional process information from the Master process into my Call Activity subprocess and wanted to check below queries.

Earlier I was using below configurations for only sending the assignee Groups information from Master to Sub process:

  1. Collection (Multi-instance): assigneeList
  2. Element Variable (Multi-instance): assigneeGrp

This works fine for sending assignee group information alone to my sub process. But now I need to send some additional information into my subprocess.

Depending on the type of group selected I choose a set of subtasks, I store the group and subtasks into a Java Map variable.

I am having trouble trying to pass and refer this additional information in my sub process.

My configurations change as below,

  1. Collection (Multi-instance): mapVariableList
  2. Element Variable (Multi-instance): mapVariable

Queries:

  • Now, How do I refer to the assignee from the Element variable?
  • My choice of using a Java Map variable is the right choice?

Appreciate your assistance.... Thank you again ....

gdharley
Intermediate

Re: How to design a process with a dynamic number of sub process tasks?

Jump to solution

Hi, I am travelling and on a deadline this week.
Will try to take a look at your question next week.

Greg