Service Catalog Variable To Get Group Members
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2009 09:06 AM
In the Service Catalog we need to be able to select a group as a variable and then select an individual that is a member of the group. This will be the individual that is assigned to the catalog task. Unfortunately the catalog reference field does not have the dependent field that is available on a form reference field so you can make the list of users dependent upon the selected group.
I have been working with two reference fields. One to sys_user_group to get a list of groups and the other to sys_user_grmember to get a list of the members of the group. I have created a function in a business rule that is called by the sys_user_grmember variable. It is returning the correct records from sys_user_grmember but it will only display the sys_id of the sys_user_grmember records. I have not been able to get the returned list to display or be selectable by user name.
Has anyone set up something where you can select a group in a reference field and then return a list of the members of the group and then select a member of the group as a variable? If someone has accomplished this I would appreciate you help in getting this to work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2009 05:57 AM
Hi Mike
Advanced Reference Qualifier for Service Catalog Variables will work for you.
http://wiki.service-now.com/index.php?title=Spring_2008_Stable#Advanced_reference_qualifiers_for_Service_Catalog_variables
Here is the effort:
1. Replace 'variable_name_for_group_reference' with the name of the variable of your group reference variable
2. Create a global business rule with the script
3. Add 'javascript:group_members()' to the Reference qual field of your user reference variable
function group_members(){
var answer = ' ';
var group = current.variables.variable_name_for_group_reference;
var group_members = new GlideRecord('sys_user_grmember');
group_members.addQuery('group',group);
group_members.query();
while(group_members.next()){
if(answer.length > 0){
answer += (',' + group_members.user.sys_id);
}else{
answer = group_members.user.sys_id;
}
}
return 'sys_idIN' + answer;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2009 08:16 AM
Thanks Kenny. Works great.
Had to make 1 little tweak. Was getting an error because the function name was group_members and was also trying to declare a variable named group_members. Change the function name to get_group_members it does exactly what we need. Thanks for your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2009 09:08 AM
The code as provided worked for me except for the issue noted where there was a variable name that was the same as the function name. The change I made was to rename the function to 'get_group_members'. After that it worked great as written.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2009 08:20 AM
Great.
I had variables/functions named differently but did a quick clean up for the post. Sorry about that. Glad you got it working.