Unhandled Exception in GlideAjax

soumya17
Tera Contributor

Hello ,

 

when i opened catalog item from portal i see "there is a javascript error in your browser console". 

i wrote client callable script to get multiple values..

soumya17_0-1677758655589.pngsoumya17_1-1677758713910.png

soumya17_2-1677758776689.png

Can someone correct me where did i do worng here..

Thanks

8 REPLIES 8

Brad Bowman
Kilo Patron
Kilo Patron

You're on the right path with the logging statements.  Add more to find out where the script is failing.  For example, is gr2 returning any records, or gr for that matter? You should declare and initialize your return variable at the beginning of the script, outside of any loops or if conditions, so that could be it - if no gr or gr1 records are returned, arr doesn't exist.  Are you certain the table name for gr2 is correct - with the misspelling of 'details'?  Use the Insert code sample icon </> in the toolbar of this editor window to paste code text, making it easier for us to read and troubleshoot.

Hello @Brad Bowman  ,

 

Yes, gr2 is returning values and the table name is also correct.

Use the Insert code sample icon </> in the toolbar of this editor window to paste code text, making it easier for us to read and troubleshoot.  .....??? can you help me to do

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@soumya17 

can you share the scripts here instead of script screenshots.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader


Client Script: 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

g_form.clearOptions('catalog_model');
g_form.addOption('catalog_model','--None--','--None--');
if(g_lang=='en'){
g_form.addOption('catalog_model','Others','Others');
} else if(g_lang=='fr'){
g_form.addOption('catalog_model','Autre','Autre');
}
var user = g_form.getReference('requested_for',callback);
function callback(user){
var country = user.u_country;
//g_form.addInfoMessage("user country is :" +country);

var ga = new GlideAjax('GetOrgIDDesktop');
ga.addParam('sysparm_name', 'checkOrgID');
ga.addParam('sysparm_user', newValue);
ga.addParam('sysparm_user_country', country);
//ga.addParam('sysparam_arche',g_form.getValue('archetype'));
ga.getXML(function(response) {
// alert("getxml");

var msg = response.responseXML.documentElement.getAttribute('answer').split(',');
for (var i = 0; i < msg.length; i++) {
g_form.addOption("catalog_model", msg[i], msg[i]);
}
g_form.removeOption('catalog_model','[object Object]');
});
}
}

Scriptinclude:

var GetOrgIDDesktop = Class.create();
GetOrgIDDesktop.prototype = Object.extendsObject(AbstractAjaxProcessor, {

checkOrgID: function() {
//gs.addInfoMessage("function");
var org = this.getParameter('sysparm_user');
var userCountry = this.getParameter('sysparm_user_country');
var gr = new GlideRecord('u_orgid_list');
gr.addQuery('u_orgid', org);
gr.addQuery('u_enabled', 'True');
gr.query();
// gs.addInfoMessage("before while si line 15 " + gr.getRowCount());
while (gr.next()) {
var entity = gr.u_entity_subscopeid;
// gs.addInfoMessage("entity subscopled line 16 " + entity);
var gr1 = new GlideRecord('u_fsl_list');
gr1.addQuery('u_country', userCountry);
gr1.addQuery('u_entity_subscopeid', entity);
gr1.query();
while (gr1.next()) {
// gs.addInfoMessage("before while si line 23" + gr1.getRowCount());
//gs.addInfoMessage("entity subscopled line 24" +gr1.u_country);
// gs.addInfoMessage("entity subscopled line 25 " + gr1.u_fsl.getDisplayValue());
var Fsl = gr1.u_fsl.getDisplayValue();
var gr2 = new GlideRecord('u_request_detials');
gr2.addQuery('u_active', 'true');
gr2.addQuery('u_entity_subscopeid', entity);
gr2.addQuery('u_fsl', Fsl);
gr2.query();
var arr = [ ];
while (gr2.next()) {
var catalogmodel = gr2.u_catalog_model.getDisplayValue();
arr.push(catalogmodel);
//arr.push(archetype);

arr.push({
value: arr.value.toString(),
label: arr.label.toString()
});
}
}
}
return arr.toString();
//return JSON.stringify(arr);
},

type: 'GetOrgIDDesktop'
});