List view help

huyjor
Tera Contributor

Hello Team

 

I have a custom table where i have different list view.

huyjor_0-1710515245793.png

But when i try to impersonate someone who has student role, or instructor role. It always goes to default view. How do i change to if i impersonate a student of instructor, it should go to one of these view. Thanks for your help. 

 

1 ACCEPTED SOLUTION

Sumanth16
Kilo Patron

Hi @huyjor ,

 

Create View Rules like below:

You have to be sure that for all users one view rule is applicable, and only one.

Dont use null, mention the view you send users who are not itil.

Here is an example you can refer to.

Sumanth16_0-1710526800009.png

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

View solution in original post

13 REPLIES 13

Sandeep Rajput
Tera Patron
Tera Patron

@huyjor You need to create a View Rule to make a user use a specific view. Please refer to the documentation https://docs.servicenow.com/bundle/washingtondc-platform-user-interface/page/administer/navigation-a... to know more about view rules.

 

Hope this helps.

Community Alums
Not applicable

Hi @huyjor ,

You can create a View Rule, follow the steps : https://docs.servicenow.com/bundle/washingtondc-platform-user-interface/page/administer/navigation-a...

 

Else, if you want to use a scripted View Rule :

(function overrideView(view, is_list) {
answer = view;

if (gs.hasRole("finance_transformation"))
answer = "Finance_Transformation";


})(view, is_list);

 

I have 2 view rules 

(function overrideView(view, is_list) {
answer = view;  // set the new view to answer
if(gs.hasRole("x_74571_kb_univ.sno_ku_student"));
answer = "student"; //student is name of list view 
})(view, is_list);
------------------------------------------------------
(function overrideView(view, is_list) {
answer = null;  // set the new view to answer
       if(gs.hasRole("x_74571_kb_univ.sno_ku_instructor"));
answer = "instructor"; //instructor is name of list view 
})(view, is_list);
 
When i impersonate a student, it shows up instructor view. And when i impersonate instructor, it also shows the same view which is instructor view. I'm not why. It could be something wrong with my code. Please help
Impersonate student or instructor. It shows up the same 
huyjor_0-1710523859035.png

 

 

@huyjor Please update your view rules as follows.

 

(function overrideView(view, is_list) {
answer = view;  // set the new view to answer
if(gs.hasRole("x_74571_kb_univ.sno_ku_student")){
answer = "student"; //student is name of list view 
}

})(view, is_list);
------------------------------------------------------
(function overrideView(view, is_list) {
answer = null;  // set the new view to answer
if(gs.hasRole("x_74571_kb_univ.sno_ku_instructor")){
answer = "instructor"; //instructor is name of list view
} 
})(view, is_list);

and check it it works correctly.