Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How can I hide records on a table based on the user's group?

jaredholm
Kilo Contributor

I would like to hide certain records on the Requested Item (sc_req_item) table based on a user's group or role.

For example, if a user submits a "Request to Pull Email" Service Catalog request, a record on the sc_req_item will be created. I want these requests to be only visible to users in the groups "ITSS-MRS Security" and "ITSS-ECS E-Mail". I have created a beforeQuery Business Rule that runs on records with item = 'Request to Pull Email', but I am having trouble with the code in the advanced section of the business rule (the code should go something like this):

if (user.group == "ITSS-MRS Security" || user.group == "ITSS-ECS E-Mail" || user.role == "admin") {
     visible = true
} else {
     visible = false
}

How do I finish this code so that only those users can see the records?

Thanks in advance.

8 REPLIES 8

Mike Patel
Tera Sage

you need something like below in script

condition: !gs.getUser().isMemberOf('ITSS-MRS Security')  && !gs.getUser().isMemberOf('ITSS-ECS E-Mail')  && !gs.hasRole("admin") 

script:

(function executeRule(current, previous /*null when async*/) {
// Add your code here
  current.addEncodedQuery('cat_item!=xxxxxxxxxxsys_id of item');
})(current, previous);

I'm not sure I understand the second half of your response. Would the script look like this?

(function executeRule(current, previous /*null when async*/) {
     if(gs.getUser().isMemberOf('ITSS-MRS Information Security') || gs.getUser().isMemberOf('ITSS-ECS Enterprise E-Mail') || gs.hasRole("admin")){
          current.addEncodedQuery('cat_item!=xxxxxxxxxxsys_id of item');
     }
})(current, previous);
 
 
How does that addEncodedQuery work? Does it hide visibility from users without those groups or roles? Do those x's need to be replaced with the actual sys_id of the record? How does it handle new records being created?

 

(function executeRule(current, previous /*null when async*/) {
     if(gs.getUser().isMemberOf('ITSS-MRS Information Security') || gs.getUser().isMemberOf('ITSS-ECS Enterprise E-Mail') || gs.hasRole("admin")){
          current.addActiveQuery();
     }
})(current, previous);

 And, I think your condition will work to check the if current logged user belongs to specific group.

hoping your have item = 'Request to Pull Email' in BR condition builder.