Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

View rule does not work for setting default view in module

Makri
Tera Contributor

Hello!

 

I have crawled and trawled through forums and other locations for help on this subject with no success.

 

I have a module called HR Profiles in a table called sn_hr_core_profiles, in the Human Resource: Core application. For most of the users ever going to use the backend part of the system we want the default view to be a view called NO Default (no_default). Now, I have tried a few scripts with view rules, the latest I have tried is this:

 

Makri_0-1717672170929.png

 

However, when I try to impersonate a user and navigate to that screen I get this: 

 

Makri_1-1717672232955.png

 

Showing that the user was NOT directed to NO Default. 

 

I have also tried to go to the Module settings and set the following:

Makri_2-1717672290879.png

 

Still, doesn't work. 

 

I know there is something I must do wrong, but I cannot understand what. 

 

3 REPLIES 3

Kieran Anson
Kilo Patron

Hey Makri!

This is very much "unless you know, you've got no chance of knowing" but ServiceNow also has a capability called Navigation Handlers which override view rules. OOB there is one for sn_hr_core_profiles which will be clearing out the view name you're specifying. Navigate to sys_navigator.list and you'll see the navigation handler. 

 

var view = g_request.getParameter('sysparm_view');
var gr = new GlideRecord(hr.TABLE_PROFILE);
if (gr.get(g_uri.get('sys_id'))) {
	if (new hr_Profile(gr, gs).canReadProfileFields()) 
		view = '';
	else  
		view = "ess";
}

g_uri.set('sysparm_view', view);
answer =  g_uri.toString('sn_hr_core_profile.do');

 

Thanks for your reply. I went to the navigation handler and checked, but it is already implemented by someone else before me. Still doesn't work I am afraid. 

Potentially I've misunderstood your issue? The following is what I've done to persist a HR profile view based on a module.

  • Created a new view and set it on the "HR Profiles" module

KieranAnson_0-1717680125474.png

  • I updated the navigation handler to persist the URI view parameter if the user has view access to the record

KieranAnson_2-1717680244832.png

From the below, you can see that I switched my list view preference for sn_hr_core_profiles to 'default'. Then when I used the 'HR Profiles' module, the view was correctly persisted to the view record

msedge_jJPwwu6vBG.gif