- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2018 06:06 AM
Hi,
Requirement:
I am trying to make an onChange script call a script include which queries the group member table for the group members of a particular group(field on the form). That script include sends back a list of users for a user table reference field on the form. I want the user field to have only this list of users available for selection.
Issue:
The response which I get from the Script include simply gets pasted in the text area of the reference field. How do I make the User table reference field options filtered to the list of user received in response.
ScreentShot:
Script Include:
var MyScript = Class.create();
MyScript.prototype = Object.extendsObject(AbstractAjaxProcessor, {
MyFunction: function(group){
var userList = [];
var grpValue = this.getParameter('sysparm_gname');
gs.log('1');
var grp = new GlideRecord('sys_user_grmember');
gs.log('2');
grp.addQuery('group',grpValue);
gs.log('3');
grp.query();
gs.log('4');
/* var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('group',group);
grp.query();*/
while(grp.next()) {
//anArray.length == 0
/* if (userList.length != 0) {
userList += (',' + grp.user);gs.log('Loop1');
}
else {
userList = grp.user;gs.log('Loop2');
}*/
// userList.push(grp.user.toString());
userList.push(grp.getDisplayValue('user'));
gs.log('Loop');
}
gs.log('@@@Test:::: ' + userList);
return userList.join();
//return 'sys_idIN' +userList.join();
// return '' + userList;
},
type: 'MyScript'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue== '') {
//Make server call
g_form.setValue('grp_mmbr_ref', '');
return ;
}
if (newValue != oldValue) {
//Make server call
var ga = new GlideAjax('MyScript');//this is the script include
ga.addParam('sysparm_name','MyFunction'); //this is the function within the script include
ga.addParam('sysparm_gname', g_form.getValue('test_item_grp_ref'));
ga.getXML(getResponse);
return;
}
function getResponse(response) {
var values = response.responseXML.documentElement.getAttribute('answer').toString().split(',');//.split('|');
g_form.setValue('grp_mmbr_ref', values);
/*g_form.setValue('description', values[1]);*/
}
}
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2018 07:17 AM
You can make the script include reusable on other fields. You simply pass it a group and it can return the members.
Your reference qualifier would be something like:
javascript:new myFilters().myGroupMembers(group_id);
The script include (called myFilters()) would have a function called myGroupMembers() that simply takes a group sys_id and looks through the sys_user_grmember table for all records with that group ID and returns a comma separated list of user IDs that go with it.
Example:
myGroupMembers : function(group_id) {
var list = [];
var mem = new GlideRecord('sys_user_grmember');
mem.addQuery('group', group_id);
mem.query();
while (mem.next()) {
list.push(mem.getValue('user'));
}
return 'sys_idIN' + list.join(',');
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2018 06:41 AM
That field is not on available service catalog items.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2018 06:47 AM
Oh Sorry My Mistake.
Let me check a code.
Thanks,
Ashutosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2018 07:13 AM
Dependencies aren't available on catalog variables. 😞

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2018 07:34 AM
Hi,
Yeah my mistake. I didnt read it properly.
Thanks,
Ashutosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2018 07:17 AM
You can make the script include reusable on other fields. You simply pass it a group and it can return the members.
Your reference qualifier would be something like:
javascript:new myFilters().myGroupMembers(group_id);
The script include (called myFilters()) would have a function called myGroupMembers() that simply takes a group sys_id and looks through the sys_user_grmember table for all records with that group ID and returns a comma separated list of user IDs that go with it.
Example:
myGroupMembers : function(group_id) {
var list = [];
var mem = new GlideRecord('sys_user_grmember');
mem.addQuery('group', group_id);
mem.query();
while (mem.next()) {
list.push(mem.getValue('user'));
}
return 'sys_idIN' + list.join(',');
},