query business rule based on knowledge article can read user criteria

selva kumar1
Tera Contributor

I have a scenario where I need to write query business rule to display knowledge article only to the users who is users of can read user criteria in article only then he should be able to read it and not using ACL 

2 REPLIES 2

selva kumar1
Tera Contributor

Sid_Takali
Kilo Patron
Kilo Patron

Hi @selva kumar1 You need to glideRecord a "user_criteria" table in query BR. Refer below script and modify accordingly

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

    var userCriteria = new GlideRecord('user_criteria');
    userCriteria.get(current.can_read_user_criteria); 
    if (userCriteria.isValidRecord()) {
        var userCanRead = userCriteria.isUserInCriteria(gs.getUserID());
        if (!userCanRead) {
            current.setAbortAction(true);
            gs.addErrorMessage('You do not have permission to read this article.');
        }
    }

})(current, previous);