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.

Set Default View Using View Rule

Jagadeesh R1
Tera Expert

Hello Team,

     I have a requirement to set a business service form to default for users with a role. I have to set it using View rule by using the advanced script. The problem I have encountered is unlike all the views ,Default view doesn't have a name. It is showing empty. How can we set the view in the script for default view? Will this be possible by using formats like view="" or view=null or even view=undefined?

This can be possible from module link view, but I am trying to find whether we can set the Default view from script in view rule

 

Regards,

Jagadeesh

 

8 REPLIES 8

Hello,

 Thank you for the reply. Is there a way to enforce the view to ITIL users without using the script in the above view rule?

 

Regards,

Jagadeesh.

i dont think so, you need to write few lines of code to fulfill this. 

 

Restrict view by role

Igor __tek
Tera Contributor

Hi @Jagadeesh R1 ,

 this is working for me:

(function overrideView(view, is_list) {
	if (gs.hasRole("admin")) {
		return; // Omit admin users
    } else {
		var urlMap = gs.action.getGlideURI().getMap();
		if((urlMap.get("portal_id") + "").length > 30) {
			return; // Omit's poral loads
		} else {
			answer = ""; // Sets default view
		}
	}

})(view, is_list);

Paul Kunze
Tera Guru

Hi, you can simply uncheck the advanced button in your View Rule and leave the field "View" empty. This will enforce the Default view.

PaulKunze_0-1737118552723.png

 

As a result, the view selection will be hidden on the table:

PaulKunze_1-1737118602886.png

 

If you need the script for something else then you can add this line to it at the end:

 

answer = '';  // enforce default