Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to Hide Form Sections?

MBarrott
Mega Sage

I'm wanting to hide the Preferences section from the Project Task form (pm_project).

 

From what I'm seeing there's no clear/easy way to flip an Active field like a lot of things on forms. 

 

Is there a simple solution to hiding form sections?

1 ACCEPTED SOLUTION

Robbie
Kilo Patron

Hi @MBarrott,

 

This is easily resolved by leveraging the following method via a UI Policy or a Client Script. (UI Policy is best practice)

 

//Example code snippet using the incident form and the 'Resolution Information' Tab/Section

g_form.setSectionDisplay('resolution_information',false);

 

Tip: The section name is lower case with an underscore replacing the first space in the name, and with the remaining spaces being removed, for example, "Section Four is Here" becomes "section_fourishere". Other non-alphanumeric characters, such as ampersand (&), are removed. Section names can be found by using the getSectionNames method.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

 

If you need advice or guidance on how to set up a UI Policy, see the following link: https://docs.servicenow.com/bundle/vancouver-platform-administration/page/administer/form-administra...

View solution in original post

16 REPLIES 16

Robbie
Kilo Patron

Hi @MBarrott,

 

Was my response helpful and enable you to hide the section? Let me know if I can help you close out this question. 

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

cczernia
Giga Guru

Just wanted to add some content for Next Experience UI.

 

While this is correct code to show/hide section:

    g_form.setSectionDisplay('section_name', true)
 
It can be tricky to find out exactly what the section name is. In UI16 you could "inspect element" and find the DOM attribute "data-section-id". However, this has the sys_id of the section now which does not work with setSectionDisplay.
 
You still need the section name. Common wisdom is this is the caption name all lower case with special characters removed and "_" replacing a space. However, this might not work now. For example, I had a section name "NCS Import Devices" and the section name ended up "ncs_importdevices".
 
If you are having trouble figuring out the section name you can use "g_form.getSectionNames()". This will print out all the section name.

- From the form you want to know the section open your browser console.
- In the console type "g_form.getSectionNames()"
- Hit enter. You should get an array of section names.