- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 07:41 AM
Hi All,
Is there any js-function to get the user list object by group-name or is there any script to get all users from a group?
example group name is: IS&T Senior Leadership Team
Thanks & Regards,
Kiran Pedduri
Solved! Go to Solution.
- 29,659 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 08:15 AM
Hi Kiran,
Sorry, I had an error in the first one. I was pushing the sys_id of the membership record, not the users. I've corrected it.
Easy change... You can 'dot-walk' to get that. If you want the user_name field (labeled User ID, like chuck.tomasi) you can change the answer.push() line to this
answer.push(mem.user.name.toString()).
You want the email,answer.push(mem.user.email.toString());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 07:44 AM
Hi Kiran,
You would need to do a GlideRecord query on the sys_user_grmember table to find the members of a group.
Example (untested): Returns an array of sys_ids for the members of a group.
function getMemberSysIds(groupName) {
var answer = [];
var mem = new GlideRecord('sys_user_grmember');
mem.addQuery('group.name', groupName);
mem.query();
while (mem.next()) {
answer.push(mem.getValue('user'));
}
return answer;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 08:01 AM
Hi Chuck Tomasi,
Thanks for the solution.
what will be the value of sys_id ? is it user_name or email_ID or User_ID
I need an array of User_ID.
Regards,
Kiran Pedduri

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 08:15 AM
Hi Kiran,
Sorry, I had an error in the first one. I was pushing the sys_id of the membership record, not the users. I've corrected it.
Easy change... You can 'dot-walk' to get that. If you want the user_name field (labeled User ID, like chuck.tomasi) you can change the answer.push() line to this
answer.push(mem.user.name.toString()).
You want the email,answer.push(mem.user.email.toString());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 11:02 AM
Hi Chuck Tomasi,
I am using below script, to update watch_list
var watchlist = current.watch_list;
gs.addInfoMessage(watchlist);
current.watch_list =watchlist + "," + addMe; // This is not working because watchlist is in encoded form where as i am appending user string to watch list.
How do I get current watch_list in user-name string format?
*********************code ***********************
(function executeRule(current, previous /*null when async*/) {
addToWatchList();
function addToWatchList() {
if(true) {
var watchlist = current.watch_list;
gs.addInfoMessage(current.watch_list);
current.watch_list = getMemberSysIds("P1 P2 Incident Watchers"); //watchlist + "," + addMe;
current.u_escalation_assigned_to = '';
//alert(current.watch_list);
}
}
function getMemberSysIds(groupName) {
var answer = [];
var mem = new GlideRecord('sys_user_grmember');
mem.addQuery('group.name', groupName);
mem.query();
while (mem.next()) {
answer.push(mem.user.name.toString());
}
// gs.addInfoMessage(answer.toString());
return answer.toString();
}
})(current, previous);
********************End***************************