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 09:09 AM
Did you include the () again after TESTAjaxCountyUtil in your reference qualifier?
javascript: 'sys_idIN' + 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 09:26 AM
That wasn't it... but I did find a typo I had. So back to it running but not returning any query results.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 09:39 AM
Is the 'zip' the correct name of the field on your current table? Or is it 'u_zip' like it is for your u_m2m_zip_counties table?
If it is u_zip, you need to update the ref qualifier accordingly:
javascript: 'sys_idIN' + new TESTAjaxCountyUtil().getCounties(current.getValue('u_zip'));
Alternatively, it might be that the current record's 'zip' field is a string value, whereas the u_m2m_zip_counties table seems to have u_zip field set as some sort of reference field meaning it will be querying on sys_ids rather than the zip code string value itself. If that is the case, then you may need to update your script include accordingly:
var TESTAjaxCountyUtil = Class.create();
TESTAjaxCountyUtil.prototype = {
initialize: function() {},
getCounties: function(zip) {
var counties = [];
var grMatch = new GlideRecord('u_m2m_zip_counties');
grMatch.addEncodedQuery('u_zip_code.name=' + zip); //update .name to the field where you store the string value of the zip code
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'
};
Also, if any of my replies have been helpful please do mark them as helpful!
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-20-2022 09:14 AM
So after mentioning this I ended up changing the config of the reference field on the form and the config of the table I am querying. Below is what ended up working. Just need to add the logic to return a specific sys_id if no records are found by the query.
var TESTAjaxCountyUtil = Class.create();
TESTAjaxCountyUtil.prototype = {
initialize: function() {},
getCounties: function() {
var zip = current.zip;
var grMatch = new GlideRecord('u_county_zip_mapping');
grMatch.addQuery('u_zip_code', zip);
grMatch.query();
var counties = [];
while (grMatch.next()) {
counties.push(grMatch.getValue('u_county_ref'));
}
return 'sys_idIN' + counties;
},
type: 'TESTAjaxCountyUtil'
};

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 08:38 AM
Is the script Include in global scope or in customer service scope?