Service Catalog Variable To Get Group Members

Not applicable

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.

14 REPLIES 14

Not applicable

I'm trying to do something similar to this. I've replicated the script in in the https://army.service-now.com/ instance. The catalog item is Test - Get Group Members. It's picking up the right information but the sysidIN statement doesn't work. What is the format for this statement?


sylvain_hauser
Tera Contributor

Any idea why the test "answer.length" is not working on my side?

I had to review the code in order to implement a counter in order to make the script working nicely:

function getSharedFolderLocation() {
var answer = '';
var count = 0; //Here is the new counter
var includes = current.variables.location;
var usr = new GlideRecord('u_cmdb_ci_network_share');
usr.addQuery('location',includes);
usr.query();
while (usr.next()) {
count += 1; //incremented each time it founds a record
if (count > 1) { //if there is more than one
answer += (',' + usr.sys_id);
} else {
answer = usr.sys_id;
}
}

return 'sys_idIN' + answer;

}


Not applicable

I put this in as a system hi ticket and the following was recommended:
function group_members(){
var answer = new Array();
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()){
answers.push(group_members.user.toString();
}

return 'sys_idIN' + answer.join();
}
It worked in our instance. We eventually were able to get both versions working.


Not applicable

Interesting solution. Thanks for posting it.


Thanks, but I think there are typos in it:

function group_members(){
var answer = new Array();
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()){
answer.push(group_members.user.toString()); //No s and a ) was missing
}

return 'sys_idIN' + answer.join();
}