Can a View rule hide the Default view from the list of Views?

Kumar60
Kilo Expert

Hello All,

Lets take a table incident.Go to the list view i.e incident.list.Click on the context menu Views as showed in the screenshot.I would like to hide the default view from some users.Is it possible through view rule?If not how to do this.

I hope the view rule is to set the view to the user,not to show in the mentioned list.Correct me if I'm wrong. :)Thanks in advance.

1 ACCEPTED SOLUTION

DirkRedeker
Mega Sage

Hi

Yes, this is possible...

 NOTE: Always check this out in QA / TEST instance FIRST !!!!

find_real_file.png

As admin, go to 

> System UI > Views

In the List, open the record for the "Default View" (see screenshot below):

find_real_file.png

In the Form, scroll down to the Related Lists:

find_real_file.png

Select the "Lists" Related List and filter it for the table, where you want to Limit the "Default View" (to be disappeared). (see screenshot above) Filter the List by the table "incident" (for example).

If there are already Records for the table on the specific user, where you want to remove the "Default View", you need to delete those records for this user first.

The one with the "user" column set to "(empty)" is the one NOT specific to any user, which are valid for ALL.

Open this record, and (for testing purposes), set this one to "some" user different to the one where you want the default view to be disappeared - save the record.

Now, the Default view disappears from the selection in the User Menu!

BUT: it just disappears, once this user has selected a View DIFFERENT to the "Default View" (which you can predefine as well). As long as he is/was showing the "Default View", it will also remain in the menu (visible). It disappears (like in the first screenshot), as soon as the user switches Views. 

Let me know, if that answers your question, please.

BR Dirk

View solution in original post

13 REPLIES 13

Yes Ankur.That user is having view_changer role.But in my script I didnt set the default view.(haven't used default view in my script)In that  case default view should hide for this user right?

 

Hi Kumar,

can you share the view rule script or condition?

even if you have some script which sets view as ABC if user has role as ABC; if that user has view_changer role that user can still switch the views from ABC to any other including default

Regards
Ankur

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

Hello Ankur,

Below is the script.

1.Now lets take user A has "Local_Admin" role and also he has view_changer role,then he is able to see the default view aswell,which I don't want.

2.For the user who has "Local_Admin",I would like to set his default list VIEW as HR_admin_One,but HR_admin_Two is getting overrided with HR_admin_One.This is because user satisfying both the conditions.(user doesn't have admin and user has Local_Admin).

So now Local_Admin should see HR_admin_One,HR_admin_Two only in the view list.

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

var UserID = gs.getUser().getID();
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('company.nameSTARTSWITHTechstar');
gr.addQuery('sys_id', UserID);
gr.query();
if (gr.next()) {
if (!gs.hasRole('admin')) {
answer = "HR_admin_One";
}
if (gs.hasRole('Local_Admin') ) {
answer = "HR_admin_Two";
}
} else {

var currentUser = gs.getUser();
var grpmember = currentUser.isMemberOf('Group1') || currentUser.isMemberOf('Group2') || currentUser.isMemberOf('Group3');
if (is_list && grpmember) {
answer = "HR_admin_Two";
} else {
var sysId = gs.action.getGlideURI().get("sys_id");
var gr_profile = new GlideRecord('sn_hr_core_profile');
if (gr_profile.get(sysId)) {
if (gr_profile.user.vip && !gs.hasRole('profile_reader')) {
answer = 'ess';
} else if (grpmember) {
answer = "HR_admin_Two";

}
}
}
}

})(view, is_list);

Hi Kumar,

I haven't worked extensively on view rules; but one thing I am aware is you can only set one view from view rule; answer variable holds the view name; if the logged in user satisfies more than 1 condition then the last script line which sets the answer variable with the view name; that view name is being used to show to the user in list

Regards
Ankur

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

Thanks for the help Ankur.I will try writing different View rule with another order.Lets see if I can achieve.The below line I couldn't see in document anywhere,so trying to the best to set multiple views for a use.

 but one thing I am aware is you can only set one view from view rule; answer variable holds the view name; if the logged in user satisfies more than 1 condition then the last script line which sets the answer variable with the view name; that view name is being used to show to the user in list