- 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 03:58 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 04:09 AM - edited 03-13-2023 04:09 AM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 04:01 AM
@Community Alums
are you sure for non-admins the script include is getting called?
are those users end users with no role?
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:10 AM
I checked the logs it is not getting called. What could be the reason?
Thanks,
Tejas
- 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