- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2025 12:41 AM
Hello All,
We have a requirement where, on the catalog form, if the Line of Business field value is selected, the SVP/VP reference field should filter and display the relevant names based on the selected value, allowing the user to choose from the options.
Currently, we have written a script include that displays the group members of the selected Line of Business in the reference field. However, in the client script, we are using the setValue method, which sets all member names to the field instead of providing a filter option for user selection.
To achieve the functionality where users can select from a filtered list, what changes should we make to the following client script?
var ga = new GlideAjax('JobGroupMember');
ga.addParam('sysparm_name', "getMembers");
ga.addParam('sysparm_organization', line);
ga.getXMLAnswer(callback);
function callback(response) {
var answer = JSON.parse(response); {
g_form.setValue("svp", answer.join(','));
}
}
}
Any help will be appreciated.
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2025 01:57 AM
is group name variable or organization variable a string type or a variable
if it's string holding group name then update your script include function as this
getMembers: function(groupName) {
var users = [];
var members = new GlideRecordSecure('sys_user_grmember');
members.addQuery('group.name', groupName);
members.query();
while (members.next()) {
var mates = members.user.sys_id.toString();
users.push(mates);
}
return 'sys_idIN' + users.toString();
}
},
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2025 12:58 AM
you need to apply advanced ref qualifier on 2nd variable so that it filters the users based on 1st
Don't use client script
please share your complete script include code here
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2025 01:18 AM
Hello @Ankur Bawiskar ,
We have used Advanced Ref qualifier for SVP field.
Here's the script include :
var JobGroupMember = Class.create();
JobGroupMember.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getMembers: function() {
var users = [];
var groupName = this.getParameter('sysparm_organization');
var gr = new GlideRecordSecure('sys_user_group');
gr.addQuery('name', groupName);
gr.query();
if (gr.next()) {
var groupSysId = gr.sys_id.toString();
var members = new GlideRecordSecure('sys_user_grmember');
members.addQuery('group', groupSysId);
members.query();
while (members.next()) {
var mates = members.user.name.toString();
users.push(mates);
}
return JSON.stringify(users);
}
},
type: 'JobGroupMember'
});
Client script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var line = g_form.getValue('organization');
if (line == 'Commercial') {
line = 'Job Request - Commercial VP/SVP';
} else if (line == 'Finance') {
line = 'Job Request - Finance VP/SVP';
}else if (line == 'Graphic Solutions') {
line = 'Job Request - Graphic Solutions VP/SVP';
}else if (line == 'HR') {
line = 'Job Request - HR VP/SVP';
}
var ga = new GlideAjax('JobGroupMember');
ga.addParam('sysparm_name', "getMembers");
ga.addParam('sysparm_organization', line);
ga.getXMLAnswer(callback);
function callback(response) {
var answer = JSON.parse(response); {
g_form.setValue("svp", answer.join(','));
}
}
}
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2025 01:57 AM
is group name variable or organization variable a string type or a variable
if it's string holding group name then update your script include function as this
getMembers: function(groupName) {
var users = [];
var members = new GlideRecordSecure('sys_user_grmember');
members.addQuery('group.name', groupName);
members.query();
while (members.next()) {
var mates = members.user.sys_id.toString();
users.push(mates);
}
return 'sys_idIN' + users.toString();
}
},
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2025 04:45 AM
Hello @Ankur Bawiskar ,
There’s an issue with the script. The logs are printed in the backend, but the reference qualifier displays "No matches found" and is not showing the filtered data.
Log:
Script :
var JobRequestVPSVP = Class.create();
JobRequestVPSVP.prototype = {
initialize: function() {},
getMembers: function(organization) {
if (organization == 'Commercial') {
organization = 'Job Request - Commercial VP/SVP';
} else if (organization == 'Finance') {
organization = 'Job Request - Finance VP/SVP';
} else if (organization == 'Graphic Solutions') {
organization = 'Job Request - Graphic Solutions VP/SVP';
} else if (organization == 'HR') {
organization = 'Job Request - HR VP/SVP';
}
var users = [];
var members = new GlideRecordSecure('sys_user_grmember');
members.addQuery('group.name', organization);
members.query();
while (members.next()) {
var mates = members.user.sys_id.toString();
users.push(mates);
}
gs.info("Users : " + users.join(','));
return 'sys_idIN' + users.toString();
},
type: 'JobRequestVPSVP'
};
Please check and let me know what changes I should make.
Thank you.