
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2018 04:31 PM
Hi All,
I am losing my mind trying to figure out what is wrong with my script include 😕 Any help would be greatly appreciated 🙂
This is related to a custom scoped application, the deliverable table has a reference field called 'Country', which comes from the x_tnmu2_nlsn_qem_tbl_Country_Master table.
When the form is loaded, and I click on the lookup using list icon (magnifying glass), the script runs successfully but produces no results in the lookup window. However, I know the script is querying correctly as the gs.log statement produces the record I want retured:
System Logs - Script Log Statements:
sys_idIN ,Canada
Here is the code I have in the country field advanced reference qualifier:
javascript:(new getCountryDetails).getCountryByRole()
Here is the code I have in the Script Include (setup as 'Client Callable'):
var getCountryDetails = Class.create();
getCountryDetails.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getCountryByRole: function(){
var gr=new GlideRecord('x_tnmu2_nlsn_qem_tbl_Country_Master');
gr.addQuery('country','Canada');
gr.query();
var answer = ' ';
while(gr.next()) {
var country = gr.getValue('country');
gs.info(country);
if (answer.length > 0) {
answer += (',' + country);
}
else {
answer = country;
}
}
gs.info('sys_idIN' + answer);
return 'sys_idIN' + answer;
},
type: 'getCountryDetails'
});
Please let me know if you require more info ... but I'm sure it is something simple that I am doing wrong. I have wrote numerous other script includes in this same way which are working fine, so I am at a loss as to why this one is not working.
Thanks in advance!!!!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2018 08:16 PM
function getCountryByRole: function() {
var countrySysIDs = [];
var countryrecord= new GlideRecord('x_tnmu2_nlsn_qem_tbl_Country_Master');
countryrecord.addEncodedQuery('country.countrySTARTSWITHCanada');
countryrecord.query();
while(countryrecord._next()) {
countcountrySysIDsry.push( countryrecord.getValue('sys_id') ); //sys_id
}
return 'sys_idIN' + countrySysIDs.join(",");
}
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2018 05:51 PM
Can't you just use the condition builder for this?
Where Country is Canada?
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2018 05:54 PM
Also, all you need is this
javascript:getCountryByRole();
Script Include "getCountryByRole"
function getCountryByRole: function() {
var countrySysIDs = [];
var countryrecord= new GlideRecord('x_tnmu2_nlsn_qem_tbl_Country_Master');
countryrecord.addQuery('country','Canada');
countryrecord.query();
while(countryrecord._next()) {
countcountrySysIDsry.push( countryrecord.getValue('country') );
}
return 'sys_idIN' + countrySysIDs.join(",");
}
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2018 06:14 PM
Thanks for the suggestions paablo .... but the result is unfortunately the same. The script executes, but nothing shows up in the lookup list, while the gs.info posts the correct results:
sys_idIN,Canada
Here is the updated script:
getCountryByRole: function(){
var countrySysIDs = [];
var countryrecord= new GlideRecord('x_tnmu2_nlsn_qem_tbl_Country_Master');
countryrecord.addQuery('country','Canada');
countryrecord.query();
while(countryrecord._next()) {
countrySysIDs.push( countryrecord.getValue('country') );
}
gs.info('sys_idIN,' + countrySysIDs.join(","));
return 'sys_idIN,' + countrySysIDs.join(",");
},
type: 'getCountryDetails'
};
Therefore, it seems it is not an issue with the script ... but the results are not being displayed.
What else could be causing the lookup list to appear empty?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2018 06:20 PM
Does the Reference Table of your field (the one using this reference qualifier) match the Reference table of the field 'country'?
I am a little confused as to why a reference qualifier is even needed here.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2018 06:25 PM
Yes, the reference field ('Country') matches the reference table field ('Country').
The ultimate goal of this script include is to limit the results that the user can see, based on their role. The Country table contains a field called 'Access_Role' ... and I thought I would loop thru the list of countries, and check if the user has the role found in the 'Access_Role' field ... and if so, I would add the country to the list of countries returned by the script.
So far, I was just trying to troubleshoot why the script was not returning any results, which is why I hard-coded the value of Canada as a test.