- 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 07:01 PM
This solution would just grab the first occurrence - and not care about a 2nd group. What do you want to have it do if it does have more than one - all the manager get approvals? - if so, change the "if" to a "while".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2018 09:29 PM
Once again thank you so much for your assistance. Manage to get it to work flawlessly!