- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 03:04 AM
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:
Please help.
Thanks,
Tejas
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 04:24 AM
@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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 04:46 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 06:03 AM
@Community Alums
since the users are end users with no role System doesn't allow calling script include. so we added that function.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 06:16 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2023 04:18 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 04:50 AM
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