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
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

15 REPLIES 15

Manikmodi16
Tera Guru

This can be achieved by creating an On Load Client Script on the form and using GlideForm method setSectionDisplay.

 

For example:

g_form.setSectionDisplay('notes',false);

 

 Replace Notes by the section name such that 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.

 

If you found this helpful, please mark this reply as solution.

 

Regards,

Manik Modi

Robbie
Kilo Patron
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...

I gave this a try but it doesn't seem to be working - am I missing something?

 

function onCondition() {
	g_form.setSectionDisplay('preferences', false);
}

 

 

Hi @MBarrott,

 

The statement looks correct. Can you clarify if you have any conditions in the 'When to Apply' tab of the UI Policy? Also, confirm you have the 'Reverse if false' checkbox unchecked.

 

To confirm the UI Policy is running when expected, add the following line in the onCondition function above the g_form statement. We will of course remove this pop-up once we've confirmed the UI Policy is running as expected.

 

function onCondition() {

alert('Running Hide Display UI Policy'); //Remove this once we've confirmed the UI Policy is running

g_form.setSectionDisplay('preferences', false);

}

 

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