how to make a section on the form visible to an assignment group

Joshuu
Kilo Sage

Hi All,

 

I have the below requirement.

 

The below 'notifications' section and the fields from the below screen shot visible only to a specific group.

 

Please assist.

 

priyarao_0-1726152547868.png

 

Regards.

 

 

 

8 REPLIES 8

Hi @Joshuu , 

check the Section backend name and try again 

you can Check the Section Name by 
Client Script :

g_form.getSectionNames();

alert()

You will get all Sections present in the Table

 

Thanks Regards , 
Badrinarayan

Badrinarayan
Tera Guru

Hi @Joshuu,

To make a specific section of a form visible only to a particular group, you can use both a Display Business Rule and a Client Script in ServiceNow. Here’s a simple way to do it:

  1. Identify the Section Name: First, you need to find the "backend name" of the section you want to control. This is the identifier that ServiceNow uses internally. To find this name:

    • Create a Client Script on the form where the section is located.

    • Use the following code in the Client Script:

       

 

var sections=g_form.getSectionNames();
alert(sections);

 

 

This code will show an alert with the names of all sections on the form. Look for the name of the section you’re interested in.

 

Write a Display Business Rule: After you have the section name, you need to control its visibility based on the user’s group. You do this with a Display Business Rule:

  • Create a new Display Business Rule that runs when the form is loaded.
  • In this Business Rule, write the logic to check if the user belongs to a specific group and then make the section visible or hidden accordingly.

Here’s a basic example of what the Business Rule might look like:

 

 

Screenshot 2024-09-13 at 3.55.09 PM.pngScreenshot 2024-09-13 at 3.56.07 PM.png

Write the Below Script in the Script Field

 

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	g_scratchpad.grp = gs.getUser().isMemberOf('Service Desk');  

})(current, previous);

 

 

 

 

Update Your Client Script: Finally, modify the Client Script to use the g_scratchpad variable to control the section’s visibility. For example:
Screenshot 2024-09-13 at 3.58.58 PM.png

 

 

function onLoad() {
    // This function runs when the form is loaded.
    // Check if the 'grp' value exists in the g_scratchpad object.
    if (g_scratchpad.grp) {
        // If grp exists, show the 'notifications' section.
        g_form.setSectionDisplay('notifications', true);
    } else {
        // If grp does not exist, hide the 'notifications' section.
        g_form.setSectionDisplay('notifications', false);
    }
}

 

 

In summary, you use the Client Script to get the section's backend name and the Display Business Rule to decide who should see it. Then, the Client Script adjusts the visibility of the section based on that decision.

 

Please Mark it as Helpful and Accept the Solution if it Satisfies , Feel free to Reply

Thanks Regards 

Badrinarayan

 

Sandeep Rajput
Tera Patron
Tera Patron

@Joshuu Please share your existing script which you are using to show/hide the sections.

SP22
Mega Sage
Mega Sage

Hi @Joshuu,

We have a similar requirement and we have used UI policy. Please find the below screenshot for your reference and let me whether it is useful or not.

Screenshot 2024-09-13 at 6.14.51 PM.pngScreenshot 2024-09-13 at 6.15.11 PM.png

 

Thanks
SP.