Unhandled exception in GlideAjax

Community Alums
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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

17 REPLIES 17

Community Alums
Not applicable

Hi @Ankur Bawiskar ,

 

Thanks, It works now. I am curious to know where and how is "isPublic" function getting called or works? could you please.

 

Thanks,

Tejas

@Community Alums 

since the users are end users with no role System doesn't allow calling script include. so we added that function.

 

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

Community Alums
Not applicable

@Ankur Bawiskar 

 

No, actually that user had ITIL role and some other 39 roles except admin but may be of some ACL, he was not able to get to that script include. It could be the possibility, right?

 

Thanks,

Tejas

Hi Tejas

Yes, had faced a similar issue & the reason for that was the script include had an ACL with role admin. You can check whether your script include has any ACLs by searching for ACL with type=client_callable_script_include.

Regards

Nikita Kale

Community Alums
Not applicable

@Ankur Bawiskar ,

 

There are some existing records of non-admins where that field is blank due to this was not working, can we populate that now?

 

Thanks,

Tejas