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

 

It looks like there was another UI Policy working against it, once disabled it appears to work. 

 

My only gripe is that the preferences section still turns up, but then vanishes after maybe 1 second (guessing the UI Policy kicking in). For me that isn't ideal and looks slightly makeshift. 

 

I'm also seeing that the section tabs are no longer rounded off on the end because Preferences is being cut off. Should it be functioning like this?

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

Hi Robbie, 

 

I created an onLoad client script with the same setSectionDisplay call and it appears to also work. I do notice that the tab is visible for a split second and then removes itself, I guess it's just loading quicker than the onLoad. 

 

If this can't be resolved then I will revert back to the UI Policy. I'm wondering if it's tied to the order of the onLoad but delaying every other onLoad didn't change anything (100 for this new call, 200 everything else). 

 

Curious on your thoughts, if we're on the same page I'll just accept the UI Policy as the solution. 

Hi @MBarrott,

 

Thinking out loud, we’re currently trying to hide the Preferences section onLoad on the Project Task form (pm_project).

Is this the only form we wish to hide this section? What other forms / tables do you leverage where you should display this section?

 

The reason I ask is, can we inverse our logic here? If it is not required or is not needed to be displayed anywhere else with the Project Task, we could remove the section from the form (Form configuration). 

Simply put, If it doesn’t need to be displayed, we can remove it and not have to worry about hiding it. (Please note, we’d be removing it from the form, not deleting it)

Another alternative would be to create a separate view for certain user groups (either by role or user base for example) to again remove it from the form.

This would again negate the need to hide it based on the UX you’re experiencing.

 

To answer your question re the order, please note you can try and set the onLoad script to 1 or a number  less than 100 (or basically any other client  script order number on the form)

 

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

 

Hi Robbie, 

 

Truthfully I don't think we need the Preferences at all so Form Config might be the way forward on this. So long as it can be brought back WHEN/IF it is needed then that should be fine. I had been under the assumption that it would need to be deleted so held off from making such changes.