Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Need to add a user to a list in Execute Script

Avatar

Level 4

Hi Friends,

I have a requirment in which i have to find the list of people who have rejected a task assigned to them. From the Task result collection output of the "Assign Multiple Task" component, I am able to find the universal Id of the participents who have approved and rejected the task. After finding the user with the Find User component, I need to add that user to a list and use that list for rsubmission of the task to those who have rejected. The below picture shows you the workflow.

listOfRejecters.JPG

I have written a script which is correct in syntax, yet does not work after the first rejctor User object is added to the list. Please find the script bellow. Kindly help me in finding a solution on how to approch this task.

import com.adobe.idp.dsc.um.lookup.datamodel.User;
import java.util.List;
import java.util.ArrayList;

User rejector = patExecContext.getProcessDataValue("/process_data/rejector");
ArrayList rejectorList = patExecContext.getProcessDataListValue("/process_data/listOfRejectors");
rejectorList.add(rejector);
patExecContext.setProcessDataListValue("/process_data/listOfRejectors", rejectorList);

In the above script, you can see that the User object rejector(local to the script) is assigned with the "/process_data/rejector" variable. and a arrayList rejectorList(local to the script) is assigned with the "/process_data/listOfRejectors" which is an empty list at the bigining of the loop.

The statement "rejectorList.add(rejector)" adds the rejector User value to the array list. and finally the rejectorList local variable is copied to the process variable "process_data/listOfRejectors". by the statement

patExecContext.setProcessDataListValue("process_data/listOfRejectors", rejectorList);

Kindly let me know is the above approch is correct. Or if there is a alternative way of creating a list of User objects.

1 Reply

Avatar

Level 10

You can choose any one of the following two approaches:

1. Inside your script activity use the method appendToProcessDataListValue to append a rejected user to the list variable

2. Use a SetValue activity instead; This is more efficient as the logic is straight forward.

I prefer approach #2.

Nith