Script Include not returning any values

reagz
Kilo Contributor

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!!!!

1 ACCEPTED SOLUTION

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

View solution in original post

18 REPLIES 18

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

Background Script:

var countrySysIDs = [];
var countryrecord= new GlideRecord('x_tnmu2_nlsn_qem_tbl_Country_Master');
countryrecord.addQuery('country','Canada');
countryrecord.query();

while(countryrecord.next()) {
gs.debug(countryrecord.getValue('sysID'));

}

gs.info('sys_idIN,' + countrySysIDs.join(","));

 

Results:

x_tnmu2_nlsn_qem: null (sys.scripts extended logging)
x_tnmu2_nlsn_qem: sys_idIN,

Why does the sysID appear NULL?

There is no such field as sysID

Look at my code above, it has the solution


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Doh!!!  I see ... sys_id ... not sysID ... ugh.

Ok, I made the change and the script is now working 🙂 🙂 🙂 🙂

Thank-you so much for guiding me thru my own stupidity 😄 lol

I feel like a script include pro now 🙂

Thanks again my friend!!