select random user from group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2020 12:12 AM
i want to select random user from a hard coded group, pls find below logic and suggest.
if it goes inside if it should consider approverList , if it goes else condition it should consider hard coded group and it should send approve randomly for any one person in group
if (approverList.length == 0) {
approverList.push(gs.getUserID());
return approverList;
} else {
var group = new GlideRecord("sys_user_group");
group.addQuery("sys_id", "d0b0871adbf45780a167d6fa4b9619a0");
group.query();
if (group.next()) {
i=0;
for( )
return group;
}
}
- Labels:
-
Multiple Versions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2020 03:55 AM
Can you keep your cursor over the activity & check for the error message.
In addition, were you able to print
gs.info("grouplast: " + group.getRowCount()+ " - " + group.group.getDisplayValue());
in logs?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2020 12:18 AM
Hi,
Try like this. Also the table should be sys_user_grmember to selelct a user from it.
if (approverList.length == 0) {
approverList.push(gs.getUserID());
return approverList;
} else {
var group = new GlideRecord("sys_user_grmember");
group.addQuery("group", "d0b0871adbf45780a167d6fa4b9619a0");
group.query();
var arr = [];
while(group.next()) {
arr.push(group.user);
}
var random_index = arr[Math.floor(Math.random() * arr.length)];
return arr[random_index];
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2020 02:11 AM
Hi Deepthi,
Did you try the code that i have provided?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2020 03:33 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2020 03:38 AM
Hi
In the workflow, check if the approval users are created correctly? Go to the record and check the approvals and see if the users are assigned or not.