There is a JavaScript error in your browser console error message appears on service portal form

siva44
Tera Contributor

Hi All,

I have created the onload  catalog client script for retrieved the data from azure  using script include and set to form field whenever open that form in portal then one error message appears " Error There is a JavaScript error in your browser console"  and not appears in Native view.

I have checked the console also it showing "Unhandled exception in GlideAjax.". and i am used the same script in some other catalog forms onload script it is showing only one catalog form remining forms not showing that error .

Onload script:

function onLoad() {
   //Type appropriate comment here, and begin script below
        var gb = new GlideAjax('AVC_Utils');
        gb.addParam('sysparm_name', "getResource");
        gb.addParam('sysparm_resource_name', "Sub Details");
        gb.getXML(SubDetails1);
 
}
       function SubDetails1(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
           
            var sub_details = answer.split(',');
          //g_form.addInfoMessage("Subscriptions  are" + sub_details);
            for (var i = 0; i < sub_details.length; i++) {
               var sub = sub_details[i].split('|')[0].toString();
               var subid = sub_details[i].split('|')[1].toString();
                 g_form.addOption("subscription_bc",subid,sub);
               
            }}

 

 

 

4 REPLIES 4

Vrushali  Kolte
Mega Sage

Hello @siva44 ,

 

Can you make below change and try.

Put the onload() function closing bracket at the very end-

 

function onLoad() {
   //Type appropriate comment here, and begin script below
        var gb = new GlideAjax('AVC_Utils');
        gb.addParam('sysparm_name', "getResource");
        gb.addParam('sysparm_resource_name', "Sub Details");
        gb.getXML(SubDetails1);
 

       function SubDetails1(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
           
            var sub_details = answer.split(',');
          //g_form.addInfoMessage("Subscriptions  are" + sub_details);
            for (var i = 0; i < sub_details.length; i++) {
               var sub = sub_details[i].split('|')[0].toString();
               var subid = sub_details[i].split('|')[1].toString();
                 g_form.addOption("subscription_bc",subid,sub);
               
            }}
} // close your onload function at the very end

 

-

If my answer solves your issue, please mark it as Accepted ✔️& Helpful👍!

 I have Tried Then also Not working

Sandeep Rajput
Tera Patron
Tera Patron

@siva44 If the Script Include is already used in other scripts then the error can be attributed to your client script.

 

Please comment the following lines in your client script and check if the error still shows up.

 

for (var i = 0; i < sub_details.length; i++) {
               var sub = sub_details[i].split('|')[0].toString();
               var subid = sub_details[i].split('|')[1].toString();
                 g_form.addOption("subscription_bc",subid,sub);
               
            }

 

You are trying to access the index 0 and 1 on the following lines directly.

 

var sub = sub_details[i].split('|')[0].toString();
var subid = sub_details[i].split('|')[1].toString();

Which may or may not be present in the sub_details string which may be a reason why the script is crashing. 

I have Tried Then also Not working