List Collector and Look Up User in Entra ID

Luiz Lucena
Mega Sage

Hi everyone, 

I'm trying to get a user list in a List Collector and pass to Look up User in Entra ID, to get the ObjectID of each user in the list to pass to the Add Users to Group in Entra ID.
However, I'm hitting a roadblock. 
I'm successfully getting the user list and passing to a For Each step, but the Look Up User in Entra ID is looking up only the first one on the list and I don't know why neither know how to solve. Also, how to pass to the Add Users to Group will be another challenge.

Screenshot 2025-09-05 at 14.45.40.png

 

EDIT: Correcting, I'm successfully getting each user Object ID from Entra ID, but not sure how to pass those users as a single batch to Entra ID to add them in the group.

9 REPLIES 9

kaushal_snow
Mega Sage

Hi @Luiz Lucena ,

 

 

Use a Lookup Records action to fetch all sys_user records matching your List Collector values.... Then feed that lookup into a For Each loop, which ensures each user is processed in turn....Inside that loop, use the Look Up User in Entra ID action for each user one by one and save each result....

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

Hi @kaushal_snow 

That part I did, and I added an "update RITM record" just to make sure we are retrieving all users ID, like shown below.
Screenshot 2025-09-09 at 11.39.51.png

 

But then, I need to add the list of users to an Entra ID group, I know would be better to add an array of users, which would require a single API call to perform that operation. 
If I try to use the action "Add User to Group", which adds one at a time, only the first one in that batch is being added. 

Here is a snippet of current flow:
Screenshot 2025-09-09 at 11.44.18.png

And I'm not sure if I should add the scripted action right after the Update RITM action OR outside the loop.
Also, I'm not quite sure if the scripted action (below) is 100% correct.

Screenshot 2025-09-09 at 11.57.35.png

can you try with below:

outputs.variable = inputs.parameter.toString().split(',');

 

and test the action and see if you are getting  output value

Glad I could help! If this solved your issue, please mark it as Helpful and Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****

No success yet. EDIT: But made some progress. 

I found this in the activity logs:

Encountered undeclared output variable: userObjectIds

Also, I modified the script to this version now:

(function run(inputs, outputs) {
  // Make a safe copy of the incoming array (or start a new array)
  var arr = Array.isArray(inputs.userObjectIds) ? inputs.userObjectIds.slice() : [];

  var id = inputs.parameter;
  if (id && typeof id === 'string') {
    id = id.trim();
    // Optional: skip duplicates
    if (id && arr.indexOf(id) === -1) {
      arr.push(id);
    }
  }

  // Optional debug log (visible in system logs)
  gs.info('Append Entra ID: ' + (id || '<empty>') + ' -> new length=' + arr.length);

  outputs.userObjectIds = arr;
})(inputs, outputs);

And I added some gs.info log, and found each user object ID in there, so we're getting close.
However the length still 1, which means, is only picking one user at a time, not the array.

Each script execution is independent - inputs.userObjectIds is not receiving the accumulated array from the previous iteration. It's always starting fresh, so arr.length is always 1.

Make sure your script step is inside a For Each action and configured properly:

 
 
For Each Item in [your collection]
├── Script Step: "Append Entra ID"
│   ├── Input: userObjectIds = [accumulated array variable]
│   ├── Input: parameter = [current item ID]
│   └── Output: userObjectIds
└── [Set accumulated array variable] = Script Step Output
Glad I could help! If this solved your issue, please mark it as Helpful and Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****