Script Include is not trigger for non-itil users

Lisa Goldman
Kilo Sage

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

 

LisaGoldman_0-1696385338955.png

 

 

 

1 ACCEPTED SOLUTION

@Lisa Goldman 

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'
});
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

20 REPLIES 20

Hi @Vishal Birajdar 

I'm still have a long way to get better at writing script.  Where and what do I need to add login logic?  

Here is the script include

var getAssetTag = Class.create();
getAssetTag.prototype = Object.extendsObject(AbstractAjaxProcessor, {

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'
});

 

Hi @Lisa Goldman 

 

Follow the below steps :

 

Step 1: Put some logs highlighted in bold

 

var getAssetTag = Class.create();
getAssetTag.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getDetails: function() {
gs.log("Inside script include");
        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'
});
 
Step 2: impersonate with non-itil users & open the catalog item from portal.
 
Step 3: Do the needful on catalog item , e.g, click on field to get asset details.
 
Step 4: End the impersonation 
 
Step 5: go to System logs >> All  in application navigator
 
Step 6: Search in message colom with text Inside script include

 

Step 7: if you are getting this log for non-itil users then users have access to script include.

 

This means users are missing Read level ACL on alm_asset table.

 

 

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Swamy Malluri
Tera Guru
Tera Guru

Hi @Lisa Goldman ,

 

Below article may helpful, have a looks

 

https://www.servicenow.com/community/developer-forum/client-script-not-triggering-for-itil-users/m-p...

 

Please mark my answer helpful and accept as solution

 

Thanks,

Swamy

Hi @Swamy Malluri 

I have reviewed the suggestion link, but it did not help much.  Thank you

Swamy Malluri
Tera Guru
Tera Guru

Hi @Lisa Goldman ,

 

Have you tried to generate logs in your script include ? are you able to call script include with end user role ? try to print logs to know till which line your code working and which is not working.

And also try to query Asset record which is assigned to end user and see the out put,

 

 

Please mark my answer helpful and accept as solution

Thanks,

Swamy