Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

record access

Jack62
Giga Guru

Evening all

 

We have an odd situation in which we have split access to records out using business rules and an ACL. the expected access works fine in list view, as in our tests users can see the right records based on conditions set but when clicking on a record it just hangs and eventually times out. My script is below, can anyone advise what is causing the issue?

 

(function executeRule(current, previous /*null when async*/) {

    //(!gs.hasRole("admin"))// is part of the Business Rule Conditions
    // task.company = user.company
    //&& (gs.hasRole("global_incident"))
    var depts = '';
    var tableN = current.getTableName();
    if(!tableN){
        tableN = '';
    }
    if(tableN == 'sc_req_item' || tableN == 'sc_task'){
        tableN = 'sc_request';
    }
    var roleN = 'global_' + tableN;
    if((gs.hasRole(roleN))){
       
        return;
        }
        else{

    var user = gs.getUserID();
    gs.log('user' + user,'domsep2');
    var encQ = 'user='+ user + '^roleLIKE_' + tableN;
   
    gs.log('encQ' + encQ,'domsep2');
    var gr = new GlideRecord('sys_user_has_role');
    gr.addEncodedQuery(encQ);
    gr.query();
    while(gr.next()){
    var role = gr.role.name;
   
    gs.log('role' + role,'domsep2');
    var dept = role.replace('_','').replace(tableN,'');
   
    gs.log('dept' + dept,'domsep2');
    if(dept != ''){
var grC = new GlideRecord('core_company');
grC.addQuery('u_abbreviation',dept);
grC.query();
while(grC.next()){

depts += '^NQcompany=' + grC.sys_id;

    gs.log('depts' + depts,'domsep2');

}
    }
    }
    gs.log(depts,'domsep2');
    var extraQuery = "company=" + gs.getUser().getCompanyID() + depts;
    gs.log('extraQ' + extraQuery,'domsep2');
    if(current.getEncodedQuery() == "" && depts == ''){
        current.addEncodedQuery(extraQuery);
    }
    else{
    var finalQ =    current.addEncodedQuery("^EQ^" + extraQuery);
        // ^EQ^ is needed to handle ^NQ (big OR) conditions
    }
    gs.log('final query' + finalQ,'domsep2');  
    }              
   
})(current, previous);
 
0 REPLIES 0