- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2018 09:20 PM
Hi,
I am trying to generate a approval for the manager of the requester in Service Catalog. However in my environment, The Manager is not filled in the Manager field in the User's profile but instead is set in Group which the user is in. The Group contains the information of the members, Manager, as well as the type, In this case the type is "assignment".
So the question is, how do I create an approval script which grabs the manager of the group which the requester is in with type "assignment" (There are other groups for providing roles but should be excluded). Oh and a user might belong to 2 or more groups, But usually only 1, Any script advise would greatly appreciated.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2018 05:26 PM
Greetings Yong,
Thank you for the quick clarity. I was uncertain if you meant they might be a member of more than one of the "assignment" type groups.
As for scripting this into your approval - when trying to build a script for this - head over to the table which contains the data you want:
sys_user_grmember in this case. (get there by doing instance.service-now.com/sys_user_grmember_list.do )
Perform a similar query to the one you want - User = Luke Wilson & group.type = assignment
Once you have performed your query in the list view and verified it does what you want - then you grab the query from the breadcrumbs (right click on the blue contains in the filter breadcrumb, and select "copy query") - something like: user=46d96f57a9fe198112947a9620895886^group.typeLIKEecdb256e4f84d30012057d218110c76c
So now you can build your query to get the group - and then the groups manager - this is going to go in place of my addEncodedQuery
var grpType = "ecdb256e4f84d30012057d218110c76c"; //this is the sys_id of the type record - will need to be adjusted to your assignment type sys_id
var grpLookup = new GlideRecord("sys_user_grmember");
grpLookup.addEncodedQuery('user='+ uservariablehere + '^group.typeLIKE' + grpType); //uservariablehere should be replaced with a reference to your user you care about might be gs.getUserID()
grpLookup.query();
if (grpLookup.next()) {
answer.push(grpLookup.group.manager.sys_id+"");
//this gets the group member record where the user is the user in question, the group is a group of type "assignment" and then grabs that groups.manager records sys_id - which is what is needed to set an approval for them.
}
Again - if you are populating a group for users - which a manager, that means you have the data in which you could populate the user.manager field - which would then allow you to easily select user.manager in the approval user field selector.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2018 02:41 PM
Greetings!
In order to provide more direction - going to need you to clarify the last bit. If the user is in more than 1 group - what do you want it to do.
Is it possible to populate the manager field for users - this is very useful for several things (ala org charts, approvals, escalations).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2018 04:31 PM
Hi Andrew,
Thank you for your reply, below are some clarifications and details of the scenario
User belongs to multiple groups, there are 2 group types. assignment and role. "assignment" is the one I am interested in, as groups with "assignment" type has the information of which Department this user belong to as well as the Manager of that department.
I am trying to get an approval script which I can insert in the Approval Workflow for Service Catalog in order to send an approval to the user's manager as the first step of approval process. Which involves checking what group the requester belongs to, of which filter out the groups to only include "assignment" group type. Then retrieve the Manager of that group.
Below is the reference approval script which I took from some other post, I'm trying to modify it or work with the scenario mentioned above as it references a specific group instead of the requester's group with assignment as type.
function getRecord(table_name, field_name, field_value) {
var n_record = new GlideRecord(table_name);
n_record.addQuery(field_name, field_value);
n_record.query();
if (n_record.next()) {
return n_record;
}
}
var group = getRecord('sys_user_group', 'name', 'ITESS - Collaboration Engineering');
var approver = getRecord('sys_user', 'sys_id', group.manager);
answer.push(approver.sys_id);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2018 05:26 PM
Greetings Yong,
Thank you for the quick clarity. I was uncertain if you meant they might be a member of more than one of the "assignment" type groups.
As for scripting this into your approval - when trying to build a script for this - head over to the table which contains the data you want:
sys_user_grmember in this case. (get there by doing instance.service-now.com/sys_user_grmember_list.do )
Perform a similar query to the one you want - User = Luke Wilson & group.type = assignment
Once you have performed your query in the list view and verified it does what you want - then you grab the query from the breadcrumbs (right click on the blue contains in the filter breadcrumb, and select "copy query") - something like: user=46d96f57a9fe198112947a9620895886^group.typeLIKEecdb256e4f84d30012057d218110c76c
So now you can build your query to get the group - and then the groups manager - this is going to go in place of my addEncodedQuery
var grpType = "ecdb256e4f84d30012057d218110c76c"; //this is the sys_id of the type record - will need to be adjusted to your assignment type sys_id
var grpLookup = new GlideRecord("sys_user_grmember");
grpLookup.addEncodedQuery('user='+ uservariablehere + '^group.typeLIKE' + grpType); //uservariablehere should be replaced with a reference to your user you care about might be gs.getUserID()
grpLookup.query();
if (grpLookup.next()) {
answer.push(grpLookup.group.manager.sys_id+"");
//this gets the group member record where the user is the user in question, the group is a group of type "assignment" and then grabs that groups.manager records sys_id - which is what is needed to set an approval for them.
}
Again - if you are populating a group for users - which a manager, that means you have the data in which you could populate the user.manager field - which would then allow you to easily select user.manager in the approval user field selector.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2018 06:57 PM
Hi Andrew,
Thank you so much, I will try out the solution. But just to check. Would this work if the user belongs to more than 1 group with assignment type?