Advanced reference qualifier not working undefined is not a function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 08:31 AM
Attempting to call a script include from an advanced reference qualifier that queries a table using the value of a string field on the form. Zip field, string, 5 digits. County field, references table that contains all counties in a state and their corresponding zip codes. Reference qualifier should return all counties associated with the Zip in the string field or "Out of state" (which is also a record in the counties table) if the Zip does not exist in the table. I'm receiving an error in the system logs com.glide.script.RhinoEcmaError: undefined is not a function. Also is this script correct to return the values correctly? Also unclear on how to return Out of State. This is in the customer service scope.
Current reference qualifier: javascript: new TESTAjaxCountyUtil.getCounties(current.zip);
Script include:
var TESTAjaxCountyUtil = Class.create();
TESTAjaxCountyUtil.prototype = {
initialize: function() {
},
getCounties: function (zip) {
var counties = [];
var grMatch = new GlideRecord('u_m2m_zip_counties');
grMatch.addQuery('u_zip_code',zip);
grMatch.query();
while (grMatch.next()) {
counties.push(grMatch.u_zip_code.sys_id);
}
return 'sys_idIN' + counties;
},
type: 'TESTAjaxCountyUtil'
};
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 08:37 AM
Hi there,
Try updating your reference qualifier as below, you are missing the () for the script include:
javascript: new TESTAjaxCountyUtil().getCounties(current.getValue('zip'));
If this answer is helpful please mark correct and helpful!
Regards,
Christopher Perry
Regards,
Chris Perry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 08:47 AM
So this worked and got past the error in the logs, thank you! I am not returning any values now though so I believe the query piece of the script include is incorrect.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 09:00 AM
Ok that is good, getting closer at least... Here are a couple more changes I would make:
1. Update your ref qualifier to be:
javascript: 'sys_idIN' + new TESTAjaxCountyUtil().getCounties(current.getValue('zip'));
2. Update your script include to be:
var TESTAjaxCountyUtil = Class.create();
TESTAjaxCountyUtil.prototype = {
initialize: function() {},
getCounties: function(zip) {
var counties = [];
var grMatch = new GlideRecord('u_m2m_zip_counties');
grMatch.addQuery('u_zip_code', zip);
grMatch.query();
while (grMatch.next()) {
counties.push(grMatch.getValue('u_zip_code'));
}
return counties.length == 0 ? 'sys_id_of_your_out_of_state_record' : counties.join();
},
type: 'TESTAjaxCountyUtil'
};
Be sure to update the return line of code with your Out of State record's sys_id. With this updated code the script include will check if there were any found records, and if there are not (array.length == 0), then return the Out of State sys_id, otherwise return a comma-separated string of the sys_ids found.
If this answer is helpful please mark correct and helpful!
Regards,
Christopher Perry
Regards,
Chris Perry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 09:07 AM
"TESTAjaxCountyUtil" is not defined returned in the system log when I added the 'sys_idIN' piece in the reference qualifier.