Query business rules based on Logged on user = one of List user

Community Alums
Not applicable

Hello expert. Need help on 'before query' business rules. Stuck for days now 😞

I have a requirement where if Logged on user is one of the user in the List below, the user can see the record.

See attached image.

Problem: when user logged in, the user sys_id is not same in any of the list even the user exist in the list. 

Any help is highly appreciated!!

find_real_file.png

find_real_file.png

7 REPLIES 7

Hi Rohana, try this code

(function executeRule(current, previous /*null when async*/ ) {
    gs.addInfoMessage("Before QR Runs---------");
    var gr = new GlideRecord(current.getTableName());
    gr.query();
    while (gr.next()) {
        var num = gr.u_group_division;// your group division field
    gs.addInfoMessage("num-------"+num);
        var num1 = num.split(','); // take sys_id of all grmember
       
        for (var i = 0; i < num1.length; i++) {
            var grp = new GlideRecord("sys_user_grmember");
            grp.addQuery("sys_id", num1[i]);
            grp.query();
            while (grp.next()) {
              
                if (gs.getUserID() == grp.user) { // if logged in user match
                    gs.addInfoMessage("In main ifffff BR");
                    current.addEncodedQuery("u_device_retired=true"); // your encoded query
                }

            }
        }
    }


})(current, previous);

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Community Alums
Not applicable

Thanks, Kalyani.

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.