- 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:19 AM
Before we focus on the technical issue, let's focus on the solution. Do you want to pick one person from the team or do you want to pick many people from the team.
In most cases with a reference field, you don't need an onChange client script to do the filtering for you, you want a reference qualifier. See the example image below.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2018 06:35 AM
Hi,
I recommend you to use glide list type field instead of reference field. I can see above that you are using reference field instead of Glide List.
Thanks,
Ashutosh Munot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2018 06:36 AM
Hey Chuck,
First thing first: BIG FAN!!!
Back to my question:
1) I am trying to achieve a functionality where I can mimic how 'Assigned to' field gets filtered based on selection made on the 'Assignment group'.
2) I am trying to implementation this on a catalog item form.
3) I want to keep the script include reusable on for other fields.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2018 06:39 AM
HI,
We make Assigned to field dependent on Assignment group.
Thanks,
Ashutosh Munot