- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago - last edited 4 hours ago
I have a client script and script include which im trying to use to narrow down the results available to select from a reference field. So far i have verified it returns the correct data (an array of sysids), but when I check if it sets that data in my reference field, it has no effect. I think my reference qualifier line might be incorrect. Can someone help? (On screen my client script alert shows - sys_idINsysid1, sysid2, sysid3 (etc) - so i think this is correct. I'm thinking I could be missing something.
Client script
function onLoad() {
var work_order_type = g_form.getValue('work_order_type');
var resolution_code = g_form.getValue('resolution_code');
var ga = new GlideAjax('x_nuvo_eam.getResolutionCodes');
ga.addParam('sysparm_name', 'getResolutionCodes');
ga.addParam('sysparm_work_order_type', work_order_type);
ga.getXMLAnswer(GetResponse);
function GetResponse(response){
alert(response);
var response1 = JSON.parse(response);
g_form.setValue('resolution_code', response1);
}
}
Script include
var getResolutionCodes = Class.create();
getResolutionCodes.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getResolutionCodes: function(){
var resolution_code_arr = [];
var work_order_type = this.getParameter('sysparm_work_order_type');
var grc = new GlideRecord('x_nuvo_eam_resolution_code');
grc.addEncodedQuery('u_work_order_typeLIKE'+work_order_type);
grc.query();
while (grc.next()) {
var resolution_code_sysid = grc.getValue('sys_id');
resolution_code_arr.push(resolution_code_sysid);
}
return 'sys_idIN' + resolution_code_arr.toString();
},
type: 'getResolutionCodes'
});
Reference qualifier
javascript: 'sys_idIN' + getResolutionCodes().getResolutionCodes(current.work_order_type).join(',');
The code doesnt narrow down the reference qualifier results at all. It just shows all results as normal. It should narrow it down based on the field passed.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
reference qualifiers are applied at server side i.e. dictionary or at variable config.
they can't be applied from client script
No client script required
In your field's dictionary use advanced ref qualifier as this
javascript: new getResolutionCodes().getResolutionCodes1(current.work_order_type);
Update Script Include as this: I changed the function name so that it's not same as script include name
var getResolutionCodes = Class.create();
getResolutionCodes.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getResolutionCodes1: function(workOrderType) {
var resolution_code_arr = [];
var grc = new GlideRecord('x_nuvo_eam_resolution_code');
grc.addEncodedQuery('u_work_order_typeLIKE' + workOrderType);
grc.query();
while (grc.next()) {
var resolution_code_sysid = grc.getValue('sys_id');
resolution_code_arr.push(resolution_code_sysid);
}
return 'sys_idIN' + resolution_code_arr.toString();
},
type: 'getResolutionCodes'
});
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
HI @anfield ,
Can you try this in your reference qualifier,
javascript: new getResolutionCodes().getResolutionCodes(current.work_order_type);
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hi @anfield ,
try this
update your script include as
var getResolutionCodes = Class.create();
getResolutionCodes.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getResolutionCodes: function(wot) {
var resolution_code_arr = [];
var work_order_type = wot || this.getParameter('sysparm_work_order_type');
var grc = new GlideRecord('x_nuvo_eam_resolution_code');
grc.addEncodedQuery('u_work_order_typeLIKE' + work_order_type);
grc.query();
while (grc.next()) {
var resolution_code_sysid = grc.getValue('sys_id');
resolution_code_arr.push(resolution_code_sysid);
}
return 'sys_idIN' + resolution_code_arr.toString();
},
type: 'getResolutionCodes'
});
and reference qualifier as
javascript:new getResolutionCodes().getResolutionCodes(current.work_order_type)
if you are still facing any issue
please share your requirement in detail with some screenshots
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya