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

Ankur Bawiskar
Tera Patron
Tera Patron

@Khalid9030 

I remember participating in your similar thread earlier and you had shared a KB article, I can't access that

so you are saying view rule is working fine but they are able to switch views?

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

@Ankur Bawiskar 

Yes, that's correct.
I'm sharing the article again. Could you try opening it in a different browser? I'm able to access it on my end.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0719228

 

 

 

 

 

@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

PrashantLearnIT
Giga Sage

Hi @Khalid9030 

 

You can remove view_changer role from users as simple.

********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************