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

Hi @MBarrott,

 

Technically you can update the section record and change the view that the 'Preferences' section is associated to. For example, change it from the Default view to the Advanced view. However, I know sections can be quite 'sticky'. You'll probably have to perform a cache.do command.

Having quickly checked this on my PDI, it does indeed seem very sticky and the cache.do has not removed the section despite updating the section record.

 

It seems the only true way to remove it cleanly is to delete the section sadly. Don't forget, this doesn't delete the fields or data contained within them for each record, it just removes the form section which you can recreate easily. 

 

I feel your pain as the pm_project form is quite heavy with all of the data points and related lists. I too observe the tab being visible on load and then disappearing a second or so later which is not the best UX.

 

@MBarrott- Can you please mark my answers to your questions correct by clicking on Accept as Solution and/or Helpful - this does not close out the thread. It does however help others in the community and recognise my effort and contribution to your question. You can mark more than one response as correct if it relates to your specific question.

 

Thanks,

Robbie

Hi Robbie, 

 

Okay we were originally on the same track. I had adjusted the view to Advanced and noticed nothing changed. I may simply delete it and recreate via an Insert and Stay if I ever need to bring it back into the form view. 

 

Greatly appreciate all the insight and feedback on this. Marked the OG fix as accepted solution. 

Thanks @MBarrott - Happy to help and glad we managed to find a solution.

 

Reach out if I can help further.

 

Thanks,

Robbie

Community Alums
Not applicable

better use on Load client script instead of UI Policy. Note that any hidden/mandatory field in your section will cause error

Hi @MBarrott,

 

I’m glad the g_form.setSectionDisplay() method worked. Would you mind marking the response correct by clicking on Accept as Solution so as to help others with a similar question or wanting to hide a form section.

 

The latency of the page load and UX does not sound ideal. What UI have you got configured? Next Experience or UI16 for example? Either way, I see no detrimental effect to the tabs. 


You could actually use the same method and syntax on an onLoad client script to help here, which as the name suggests will be executed on load. Ensure the onLoad script is one of the first scripts to be called by leveraging the 'Order' column.

I appreciate we discussed client scripts vs UI Policies. the reason why a UI Policy is best practice (and why I recommended to use a Ui Policy) is because of the call order. UI Policies are executed last meaning you can have control how the page appears after the page has finished loading. Anything within an onLoad script can still be updated/changed if the same field or manipulation is called within a UI Policy. It sounds like you may have to handle it via an onLoad script but as you mentioned ensure no other UI Policies also look to update the same field or form etc.

 

Thanks,

Robbie