Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

View rules for restricting admin

kumaraj
Kilo Sage

Hi Team,

Hope you all are fine,

 

I have a requirement to create a View rule for document management (ds_document) table so that the Newly created view for form and list can be seen only by a ABC group, even an admin should not see it.

View name - Security view

Group name - ABC (Only this group can see the records, even admin should not see it)

 

script in view rule:

(function overrideView(view, is_list) {

    // Add your code here
    answer = null;  // set the new view to answer
  
        if(gs.getUser().isMemberOf("DM Security group")){
            answer += "security_view";
        }
else {
answer = null;
}
       

})(view, is_list);
2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@kumaraj 

Did you check if the view rule runs for admin? did you debug by adding logs?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Runjay Patel
Giga Sage

Hi @kumaraj ,

 

Use below code.

 

 if(gs.getUser().isMemberOf("DM Security group")){
            answer = "security_view";
        }
else {
answer = null;
}

Add role to manage view.

RunjayPatel_0-1730900398282.png

 

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------