how to make a section on the form visible to an assignment group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2024 08:00 AM
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.
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 03:39 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 03:33 AM
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:
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:
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:
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 05:31 AM
@Joshuu Please share your existing script which you are using to show/hide the sections.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 05:46 AM
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.
Thanks
SP.