- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 07:11 PM
Hello,
I have a script includes that query 'alm_asset' table to retrieve asset tag. It's working fine as an admin or ITIL user, but when I impersonate an end user with no roles, no data is returned."
Could someone please help? Here is the script include for your review. Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 08:46 PM
it should be simply this
var getAssetTag = Class.create();
getAssetTag.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isPublic:function(){
return true;
},
getDetails: function() {
var arr = [];
var sysId = this.getParameter('sysparm_sysId');
var gr = new GlideRecord('alm_asset');
gr.addQuery('assigned_to', sysId);
gr.addQuery('asset_tag', '!=', '');
gr.query();
while (gr.next()) {
arr.push(gr.asset_tag.toString());
}
if (arr.length >= 2)
return arr.toString();
// else
// return '';
},
type: 'getAssetTag'
});
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 08:23 PM
This is how you would add a log in the script include? After adding gs.log, login as the user, then run it is that right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 08:29 PM
Hi @Lisa Goldman ,
Try adding more logs and see what result you are getting. And make sure you have valid asset assigned to logged in user in Asset table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 08:35 PM
Please add the isPublic function so that it works for end user with no roles
I included this function inside the script include
isPublic:function(){
return true;
},
var getAssetTag = Class.create();
getAssetTag.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isPublic:function(){
return true;
},
getDetails: function() {
var arr = [];
var sysId = this.getParameter('sysparm_sysId');
var gr = new GlideRecord('alm_asset');
gr.addQuery('assigned_to', sysId);
gr.addQuery('asset_tag', '!=', '');
gr.query();
while (gr.next()) {
arr.push(gr.asset_tag.toString());
}
if (arr.length >= 2)
return arr.toString();
// else
// return '';
},
type: 'getAssetTag'
});
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
10-03-2023 08:42 PM
Thank you @Ankur Bawiskar
I would like to try what you have suggested, but encountering an error in the code:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 08:46 PM
it should be simply this
var getAssetTag = Class.create();
getAssetTag.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isPublic:function(){
return true;
},
getDetails: function() {
var arr = [];
var sysId = this.getParameter('sysparm_sysId');
var gr = new GlideRecord('alm_asset');
gr.addQuery('assigned_to', sysId);
gr.addQuery('asset_tag', '!=', '');
gr.query();
while (gr.next()) {
arr.push(gr.asset_tag.toString());
}
if (arr.length >= 2)
return arr.toString();
// else
// return '';
},
type: 'getAssetTag'
});
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader