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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2022 01:28 AM
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!!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 01:13 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2022 07:42 PM
Thanks, Kalyani.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2022 09:40 PM
Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.