Restrict Form Views by Role

From SNCWiki

Jump to: navigation, search
Role required
Functionality described here requires the Admin role.
As-is functionality
Caution: The customization described here was developed for use in specific Service-now instances, and is not supported by Service-now Customer support. This method is provided as-is and should be tested thoroughly before implementation. Post all questions and comments regarding this customization to our community forum.

Name: Restrict Form Views by Role

Type: Business Rule

Table: global

Description: Generally the view used on a form is controlled by either specifying the sysparm_view parameter in the url or module properties, or by inheriting the view from the previous form or list. In some cases this does not apply, such as opening a referenced field form from a record producer. In this case you may want to control the view of the form based on roles. Here's an example of controlling the view of the user form.

This script is based off of the out-of-box global business rule incident functions.

Parameters:

Script:
//Force non-itil users to the ess view for sys_user
 
//To use on other tables, replace sys_user with the table name
 
//Business rule: User View Filter
//Table:global
//Runat:server
 
function sys_userGetViewName() {
if (gs.hasRole("itil"))
{return; }
if (view.startsWith("ess"))
{return;}
// do not change view if it starts with sys_ (e.g. sys_ref_list)
if (view.startsWith("sys_"))
{return;}
answer = "ess";
}
 
function sys_user_listGetViewName() {
sys_userGetViewName();
}
Personal tools
Print/export