multi-instantiated process for every user in a group

1
0
-1

Hi, I'd like to start a process instance for every user in a group. I've tried to create a process variable that contains the user's list. This variable has this default value:

final IdentityAPI identityAPI = TenantAPIAccessor.getIdentityAPI(apiSession);
final SearchOptionsBuilder builder = new SearchOptionsBuilder(0, 100);
builder.filter(UserSearchDescriptor.GROUP_ID, groupID);
final SearchResult<User> userResults = identityAPI(apiSession).searchUsers(builder.done());

But I have 2 problems:

  1. where can I retrive the groupID?
  2. TenantAPIAccessor, UserSearchDescriptor and apiSession cannot be resolved and may lead to runtime errors.

Thank you!

1 answer

1
0
-1

The way we did this was something like as follows:

// get the group (organization path)
// sample def organization = "acme", group = "finance"
// note: VERY case sensative - must make sure the path is correct in Manage Organization (Studio)

String fullOrganizationPath = "/"+organization+"/"+group;
Group groupSelected=apiAccessor.getIdentityAPI().getGroupByPath(fullOrganizationPath);

// get the users in the group
List<User> usersInGroup=apiAccessor.getIdentityAPI().getUsersInGroup(groupSelected.getId(), 0, 100, UserCriterion.FIRST_NAME_ASC);

// return list with user details (names, emails, etc.)
final List<List<Object>> resultTable = new ArrayList<List<Object>>();

// do for each user in group
for (User user : usersInGroup){
 
         // create the row data
         final List<Object> row = new ArrayList<Object>();
         
         //get professional contact data
         UserWithContactData contact = apiAccessor.getIdentityAPI().getUserWithProfessionalDetails(user.getId());
         if (contact!=null){
                 row.add(user.getJobTitle()+"("+user.getFirstName()+" "+user.getLastName()+")");
         }
         resultTable.add(Collections.unmodifiableList(row));
 }
// return a list of user details (can be anything you need from the details of the user.
return resultTable;

That gets all the users in a group:

To assign tasks to a user - we do not do this all in one step - we find it more reliable to separate into three

1) create the task;
2) wait for the backend to create the task; //very important
3) assign the task to the user...

I cannot give you all the details for understandable reasons however this in summary is how we do this:

1) create the task; Service Step 1

// get the list of processes
List<ProcessDeploymentInfo> processSet = processAPI.getProcessDeploymentInfos(0, 2000, ProcessDeploymentInfoCriterion.NAME_ASC);

// search the list for the process you want and the active version.  There will be multiple definitions in the list, depends on which one is active, that's the one you want.
// code not given

// get the process id - as you can see getprocess id requires version number
processId = processAPI.getProcessDefinitionId(processToStart, latestVersion);

// loop the users
for (String username : userNames){

// IF sending process data here is a sample
Map<String, Serializable> processData = new HashMap<String, Serializable>();
processData.put("to_process_variable_1", from_process_variable_1);
processData.put("to_process_variable_2", from_process_variable_2);
processData.put("to_process_variable_3", from_process_variable_3);
                                               
// Start the process
ProcessInstance processInstance = processAPI.startProcess(processId, processData);

// save the processInstance into a list of long - we'll use this in the assignment phase
}

return saved list of processInstance;

2) wait for the backend to create the task; //very important

we use a timer between the two steps - we give it 15 seconds - not ideal because on a quick system some processes look as if they are generally available - they will disappear after a short time though.

3) assign the task to the user... Service Step 2

//get the list of human tasks outstanding
                SearchOptionsBuilder searchOptionsBuilder = new SearchOptionsBuilder(0, 100);
                searchOptionsBuilder.filter(HumanTaskInstanceSearchDescriptor.NAME, processIdent[0]);
                SearchOptions searchOptions = searchOptionsBuilder.done();
                SearchResult<HumanTaskInstance> searchHumanTaskInstances = processAPI.searchHumanTaskInstances(searchOptions);

// loop human tasks
                for (HumanTaskInstance pendingTask : searchHumanTaskInstances.getResult()) {

//make sure it's the right one
                        if (pendingTask.getParentProcessInstanceId().toString().equals(processProcessId[1].toString())){
                       
// and get the Activity ID
                                if (pendingTask.getId()>activityId){
                                        activityId = pendingTask.getId();
                                }
}

// and finally assign the task to the user
                                processAPI.assignUserTask(activityId, userid.getId());

//here is also an example of how to update the due date from the default.
// due dates can be manipulated by task not by process

                                processAPI.updateDueDateOfTask(activityId, dueDate);

}

Code for setting a new date // depending on what day it is.

Calendar c = Calendar.getInstance();
int weekday = c.get(c.DAY_OF_WEEK);
if (weekday == c.MONDAY){c.add(c.DAY_OF_MONTH,3)}
if (weekday == c.TUESDAY){c.add(c.DAY_OF_MONTH,5)}
if (weekday == c.WEDNESDAY){c.add(c.DAY_OF_MONTH,5)}
if (weekday == c.THURSDAY){c.add(c.DAY_OF_MONTH,5)}
if (weekday == c.FRIDAY){c.add(c.DAY_OF_MONTH,5)}
if (weekday == c.SATURDAY){c.add(c.DAY_OF_MONTH,4)}
if (weekday == c.SUNDAY){c.add(c.DAY_OF_MONTH,3)}
c.setTime(new Date()); // Now use today date.
c.add(Calendar.DATE, 3); // Adding 3 days

Date dueDate = c.getTime();

There you have it,

1) code to get a group of users
2) code to create the process // and how to pass process variables
3) code to assign the process human task to the user // and how to change the task dueDate

Hope this helps and I hope you understand why I can't give you everything...it's confidential.

regards
Seán

PS: As this completely answers your question, please mark as resolved.

Notifications