How to check and set a form view

ericgilmore
Tera Guru

I just created a simple onLoad script to check and set a form view on an Incident.

// Simple onLoad script

function onLoad() {
	
	var view = getView().toString();
	
	if(view == '') {
		switchView('section','incident','mobile');
	} 

	return;
   
}

My issue is that I didn't find any documentation for this. Does this mean that this is an un-supported, un-documented way to check and set form views?

And that it may go away at any time with future version updates?

If this is un-documented and volatile, what's the proper way, when using an onLoad script on the client side, to get and set a form view?  

1 ACCEPTED SOLUTION

Shillu
Kilo Guru

Checkout View Rules, Eric.

https://docs.servicenow.com/bundle/madrid-platform-user-interface/page/administer/navigation-and-ui/task/t_CreateAViewRule.html

View solution in original post

5 REPLIES 5

Shillu
Kilo Guru

Checkout View Rules, Eric.

https://docs.servicenow.com/bundle/madrid-platform-user-interface/page/administer/navigation-and-ui/task/t_CreateAViewRule.html

Thank you, Shillu!

find_real_file.png

Dave49
Giga Contributor

Good Afternoon

Thank you all in advance for your help.

I have tried to create the View Rule 2 different ways.

1) Using the Advanced view, i.e. a script
(function overrideView(view, is_list) {

    var currentUser = gs.getUser();
    var userGroupGP_CSP = currentUser.isMemberOf('GP CSP');
    if (userGroupGP_CSP) {
        answer = 'CSP Team'; // set the new view to answer;
    }

})(view, is_list);

The script runs and the userGroupGP_CSP variable is set correctly (I walked through it in the debugger) but the view is not set.

So I tried a second method.

2)find_real_file.png

Please note: We are in a Domain Separated environment so in both cases the View Rule was created in the Top Domain of this client.

 

Neither method works. What am I missing?

After I found out about them, I love view rules. I've also found that if I have a view with a space in the name, I had to add an underscore to get it to work.

I was using Madrid at the time, but I've carried that over whenever I create a new view rule and it seems to be needed.

So on the view rule entry, instead of view [ CSP Team ]

Make it view [ CSP_Team ] and give that a try.

I don't know if that's documented anywhere, but it works on my instances.