- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 04:01 AM
Hello guys,
For a catalog request, i want to update all the incidents. Where assigned or caller is a user who is part of requester's group/groups.
Using below script to get the information. But it is very time taking, as i have to parse multiple incidents.
Could anybody suggest me a better way to do this
var sg = new GlideRecord('sys_user_grmember');
sg.addQuery('user', requester);
sg.query();
var group_list = [];
var num = sg.getRowCount();
while (sg.next()) {
gs.info('groups found' + num);
group_list.push(sg.group);
}
for (var j = 0; j < group_list.length; j++) {
var users = [];
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('group', group_list[j]);
grp.query();
while (grp.next()) {
users.push(grp.user);
gs.info('user name ' + users[j].getDisplayValue());
}
}
Solved! Go to Solution.
- Labels:
-
Request Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2020 04:40 AM
You got above code working right? So "requester" variable is already set somewhere in the code?
Then this will improve the speed. It will only trigger 2 queries instead of 1 query, plus additional queries for each group:
var sg = new GlideRecord('sys_user_grmember');
sg.addQuery('user', requester);
sg.query();
var group_list = [];
var num = sg.getRowCount();
while (sg.next()) {
gs.info('groups found' + num);
group_list.push(sg.group);
}
var users = [];
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('group', 'IN', group_list);
grp.query();
while (grp.next()) {
users.push(grp.getUniqueValue());
gs.info('user name ' + grp.getDisplayValue());
}
//now you have an array of users you can use for an "IN" on the incident table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2020 04:25 AM
I tried this approach, but it did not work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 04:24 AM
Hi Harsha,
Can you explain what are you trying to perform?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 04:34 AM
Hi,
I need to get all the users, who are part of the same groups as the requester of the catalog item .
In other words, i need to find all my team mates, even if i am part of different teams
I need to compare them to assigned or caller of the incidents..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 05:00 AM
So is that requester a variable on your catalog item or you are saying the user who requested for the catalog item?
I assume your script is in workflow run script of Catalog Item or BR on sc_req_item
sg.addQuery('user', current.variables.<requesterVariable>); // give proper variable name here
if you are saying requested_for field of sc_request then it should be like this
sg.addQuery('user', current.request.requested_for);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2020 04:28 AM
I need to query all users who are part of the requester's group
For example
Archie is part of HR and MR groups.
If archie is the requester, my query will be like
sg.addQuery('user', users of both HR and MR groups);