How Can I Default Value of a list reference to sys_user to be all users in a specific group?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2022 12:04 PM
Hi All,
I have a list field that is referencing the sys_user table (u_user). I have a requirement to pre-populate this list reference with all users from a specific group (Manager Group)
How can I set the default value for my u_user list reference to include all users from a specific group (Manager Group) when someone creates a new record?
I've looked on the forums and online and haven't been able to find anything that would accomplish this. I don't want to hardcode the user names in the default value and want it to dynamically populate with whatever users are in a specific group.
Any ideas??
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2022 12:18 PM
Hi,
You can use a business rule, before insert on that table.
The business rule script can populate the field.
Something like:
var userList = [];
//Query your reference data
var rec = new GlideRecord('sys_user_grmember');
rec.addQuery('group', groupName); //replace group name with manager group
rec.query();
//iterate through the results and push records into an array
while (rec.next()) {
userList.push(rec.sys_id.toString());
}
//Now convert the array to a string and populate to the list field.
var userString = userList.toString();
current.u_user = userString; //replace list field with
Hope that helps.
Please mark my answer as Correct/Helpful based on impact
Regards,
Dan H
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 07:34 AM
Hi Dan,
Thanks for the response! I am wanting the field to populate on the form while a user is creating it so I was trying to avoid using the business rule approach you mentioned.
I tried doing something similar with a script include and default value like Deepankar mentioned but no luck yet.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 09:16 AM
Hi I realised that my script wont work anyway, and neither the other posted here.
The best way to do is, is with a Script include and Client Script utilising GlideAjax.
It is trivial to get the list of users that need to be populated onto the form, but it is not trivial to populate the users into a List variable.
This is the best reference I could find on how to do this, though it doesn't fit your requirement perfectly: https://community.servicenow.com/community?id=community_blog&sys_id=a60c397edb04dc1c190dfb24399619b1

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2022 12:19 PM
Hi Carter,
You can call a script include in your default value field. In that script include you can call "sys_user_grmember" table. Put the condition in the addQuery as group is Manager group.
Hence returning the users in the default value.
Regards,
Deepankar Mathur