Convert ACL to before query BR

Ak8977
Tera Expert

can anyone help me to convert the ACL code into before query BR.

if (gs.getSession().isInteractive() && (new sn_hr_core.hr_CoreUtils().impersonateCheck()))
    answer = false;
else if (new hr_Case(current, gs).canReadCase())
    answer = true;
else
    answer = false;
4 REPLIES 4

Maddysunil
Kilo Sage

@Ak8977 

Below is the sample before query BR you can modify:

 

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

    // Check if the session is interactive and not impersonating
    if (gs.getSession().isInteractive() && (new sn_hr_core.hr_CoreUtils().impersonateCheck())) {
        return;
    }
    // Instantiate hr_Case object
    var hrCase = new hr_Case(current, gs);  
    // Check if the current user can read the case
    if (hrCase.canReadCase()) {
       current.addActiveQuery();//you can write your own logic here
    } 

})(current, previous);

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

Hello sunil,

I am aware of using the addActiveQuery(). But the hrCase.canReadCase() do lot of validations like it can check the user has respective roles, weather any of the COE security policies met with the respective user.

I can include roles in the  activequery() but what about COE security policies, how I can set it in the query

Dipen Wadhwana
Giga Guru

Hi @Ak8977 ,

 

Can you please try this:

(function executeBeforeQuery(current, previous /*null when async*/ ) {
    var answer = false;
    if (gs.getSession().isInteractive() && (new sn_hr_core.hr_CoreUtils().impersonateCheck())) {
        gs.log("Impersonate check failed. Access denied.");
    } else if (new hr_Case(current, gs).canReadCase()) {
        answer = true;
    } else {
        gs.log("User does not have permission to read the case. Access denied.");
    }

    if (!answer) {
        current.setLimit(0);
    }
})(current, previous);

Please modify the script as per your logic requirements. 

 

Please mark this response as helpful if your question has been answered correctly.

Hello Dipesh it won't work. In query business rule we have to use addQuery() or addEncodedQuery().