- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 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
2 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
2 hours ago
I think your reference qualifier should be something like this:
javascript:'sys_idIN'+getIDs(current.work_order_type); function getIDs(woType){var ids=getResolutionCodes.getResolutionCodes(woType).join(','); return ids;}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 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
2 hours ago
Hi. So ive tuned off the client script and made the updates as you suggested. Doesnt seem to have any affect. That script include is actually in another app, so the api is listed as
"x_nuvo_eam.getResolutionCodes"
script name: getResolutionCodes
Set the reference qual as you suggested, and also tried the line below. Neither has any affect.
javascript: new x_nuvo_eam.getResolutionCodes().getResolutionCodes1(current.work_order_type);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Cannot see the above code even firing. Added some logs at the top of the script include, nothing