We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Unhandled exception in GlideAjax

Not applicable

Hi All,

 

I am getting unhandled exception in GlideAjax

 

I have created below:

Catalog Client Script:

var rf = g_form.getValue('requested_for');
var ga = new GlideAjax('getAssets');
ga.addParam('sysparm_name', "getAssetsList");
ga.addParam('sysparm_user', rf);
ga.getXML(setAnswer);
return false;
function setAnswer(answer) {

if (answer == 'false') {
g_form.addErrorMessage('There is Sweet Mistake in Logic');
return false;
}
var arr = JSON.parse(ga.getAnswer());
if (arr.length==0){
g_form.clearValue('asset_to_be_collected');
}
var assets = '';

for (var i = 0; i < arr.length; i++) {
var temp = 'Asset ' + (i + 1) + /*': '*/ '\n';
temp += "Asset Name: " + arr[i].dn + ", ";
temp += "Asset Tag: " + arr[i].at + ", ";
temp += "Serial Number: " + arr[i].sn;
assets += temp + '\n\n';

g_form.setValue('asset_to_be_collected', assets) +'/n';
//g_form.setReadOnly('asset_to_be_collected', true);

}

}

 

Script Include:

getAssetsList: function() {
var user = this.getParameter('sysparm_user');
var arr = [];
var gr = new GlideRecord("alm_hardware");
gr.addQuery("assigned_to.sys_id", user);
gr.query();
//gs.log("Test User" + gr);
while (gr.next()) {
var obj = {};
obj.dn = gr.display_name.toString();
obj.at = gr.asset_tag.toString();
obj.sn = gr.serial_number.toString();
arr.push(obj);
}
var data = JSON.stringify(arr);
//gs.log("My assets are - "+ data);
return data;


},

 

Getting below error in portal:

Tejas12_0-1678701835023.png

 

Please help.

 

Thanks,

Tejas

1 ACCEPTED SOLUTION

@Community Alums 

possibly it's not getting called for end users with no role

add this function to your script include

isPublic:function(){
return true;
},

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

17 REPLIES 17

Not applicable

Hi @Prince Arora ,

 

Hi Anand,

 

As a Admin I am getting expected output with code I have pasted but when I impersonate to the ITIL user it is not fetching any data and throws "There is javascript error in your browser console".

 

Thanks,

Tejas

@Community Alums ,

Please check for two points:

1) Do NON-admin users can call that script include
2) Do they have the access to "alm_hardware" table.

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

Ankur Bawiskar
Tera Patron

@Community Alums 

are you sure for non-admins the script include is getting called?

are those users end users with no role?

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

Not applicable

Hi @Ankur Bawiskar 

 

I checked the logs it is not getting called. What could be the reason?

 

Thanks,

Tejas

@Community Alums 

possibly it's not getting called for end users with no role

add this function to your script include

isPublic:function(){
return true;
},

If my response helped please mark it correct and close the thread so that it benefits future readers.

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