Issue with View Rule: Users with 'view_changer' Role Able to Switch Views on Requestor Table Despite

Khalid9030
Tera Contributor

Hello All,

 

Requirement :

 

We want to prevent users with the "View_changer" role from changing the view on the Requestor table—both at the form level and list level—without affecting other tables. However, Admin users should be exempt from this restriction.

 

I have implemented a View Rule for the view_changer role. When I impersonate a user with the view_changer role, they are able to see the requestor_details_view by default. However, they are also able to switch to other views, but they cannot access the default view. Could you please suggest what the issue might be?

 

View rule code 

(function overrideView(view, is_list) {

    // Add your code here

    if(gs.hasRole('view_changer') && !gs.hasRole('admin')){

       

    answer = 'requestor_details_view' ;  // set the new view to answer

    }

    else{

        answer = view;

    }

})(view, is_list);

1 ACCEPTED SOLUTION

@Khalid9030 

I believe then it's not possible to achieve your case.

With that KB it says they can change/switch the view but the view rule will run again and set the view

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

5 REPLIES 5

@PrashantLearnIT 

Thanks for your reply. 

Our client's requirement is to prevent users with the 'View_changer' role from changing the view on the Requestor table only, while still allowing them to switch views on other tables.