View Rules - Force the DEFAULT view? Not working

Duncan Pederse1
Giga Expert

Has anyone ever used a View Rule to force users to see the 'Default view'? I checked in sys_ui_view and it seems the Default view does not have a name (it is empty). Therefore I do not know what to return from my view rule. I am returning an empty string, but it is still allowing the users to change the view.

8 REPLIES 8

Jagadeesh R1
Tera Expert

Hello,

   Assuming that users are accessing the records from a module taking them to a list of records and then users are selecting a record from the list (i.e  Incident-->Open--->record). You can enforce the user preference of the view in the module arguments

sysparm_userpref.tablename_list.view=viewone&sysparm_userpref.tablename.view=viewtwo

 

So for example if you want to enforce users to have a default list view for incident list and record from module, you can give below arguments

sysparm_userpref.incident_list.view=&sysparm_userpref.incident.view=

Since default view has no value I have replace the viewone and viewtwo with blanks 

 

Regards,

Jagadeesh

Hi,

Thanks so much for this response!! I've spent so much time before I finally saw this solution.
What a relief that finally something works.

Maybe the only remark is that it worked for me in this form:

&sysparm_userpref.incident.view=default

Thanks again,
Aniko

pawan k singh
Tera Guru

You can create a view Rule like below.

find_real_file.png

Please mark this answer correct, if it helped you!

Regards

Pawan K Singh

sumanta pal
Kilo Guru


Yes, you can use a View Rule to force users to see the 'Default view'. Here are the steps to do it:

1. Navigate to System UI > View Rules in your ServiceNow instance.
2. Click on New to create a new View Rule.
3. Fill in the necessary fields. In the 'View name' field, leave it blank as the Default view does not have a name.
4. In the 'Script' field, write a script that determines when this rule applies. If you want this rule to apply to all users, you can return true from this script.
5. Click on Submit to save the View Rule.

Here is a sample script that you can use in the 'Script' field:

javascript
function onView(context) {
// Replace this condition with your own
if (gs.getUserID() == context.user) {
return '';
}
}


This script will force the user to see the Default view if their user ID matches the context user.

Please note that this is just a sample script and you may need to modify it according to your requirements. Also, keep in mind that View Rules are evaluated in order, so make sure to order your rules correctly.

In summary:

- Navigate to System UI > View Rules.
- Create a new View Rule.
- Leave the 'View name' field blank for Default view.
- Write a script in the 'Script' field that determines when this rule applies.
- Save the View Rule.
- Make sure to order your View Rules correctly.


nowKB.com