Calling script include in ACL

Rajamouly
Tera Expert

Hi All,

 

I have a requirement of create a customized table with two fields called User(abc) and CMDB CI Class(windows)

We need to write a function in script include that only user and class matching we should return true, Else it should look return false.

This script include again we are calling in ACL so that User from customized table only create CI, if user not present then we need to check else condition(check parent class is matching with our customized table class)

 

Script include name :WBC_INFY_CMDB_Framework();

CICreationAllowedForUser: function(ci){
var access1= this.checkLoggedUser(ci);
var cmdbclass= new GlideRecord('u_cmdb_users_classess');
cmdbclass.addEncodedQuery('u_userANYTHING^u_cmdb_class=Windows Server');
cmdbclass.setLimit(1);
cmdbclass.query();
if(cmdbclass.next()){
return true;
}
else {
var cmdbclass1= new GlideRecord('cmdb_ci');
cmdbclass1.addQuery('sys_class_name',cmdbclass.u_cmdb_class);//match
cmdbclass1.setLimit(1);
cmdbclass1.query();
if(cmdbclass1.next()){
return false;
}

 

ACL:

var cmdbACLHelper = new WBC_INFY_CMDB_Framework();

if  (cmdbACLHelper.CICreationAllowedForUser(gs.getUserID(), current.sys_class_name)) {
answer=true;
}

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

So what debugging you performed?

Regards
Ankur

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

Hi @Ankur Bawiskar 

The ACL is working fine for If condition, even if the user is not present in customized table then it is not going for else condition.(Always creating CI class)

Hi,

use hasNext()

CICreationAllowedForUser: function(ci){
    var access1= this.checkLoggedUser(ci);
    var cmdbclass= new GlideRecord('u_cmdb_users_classess');
    cmdbclass.addEncodedQuery('u_userANYTHING^u_cmdb_class=Windows Server');
    cmdbclass.setLimit(1);
    cmdbclass.query();
    if(cmdbclass.hasNext()){
        return true;
    }
    else {
        var cmdbclass1= new GlideRecord('cmdb_ci');
        cmdbclass1.addQuery('sys_class_name',cmdbclass.u_cmdb_class);//match
        cmdbclass1.setLimit(1);
        cmdbclass1.query();
        if(cmdbclass1.next()){
            return false;
        }

Regards
Ankur

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

HI,

I removed else part but i am not sure if it is calling this function in ACL or not.

find_real_file.png

Checked in background scripts it is validating the function and giving output

find_real_file.png