logo

NJP

How To: Using UI Policies to hide form sections

Import · Feb 12, 2022 · article

I have seen this a few times in the community and wanted to do a quick post about hiding form sections by UI policy. In my case, I am going to be hiding based on my amazon connect business services.

Form sections are a little different than regular fields. They have an underlying value like any field on the form but they aren't the same. If you have a form field called "This Is a Form" you would expect the value you to be "this_is_a_form". Sections, on the other hand, go like this: Your section name is "This is a section" but the underlying value will be "this_isasection". notice the structure, The first space uses an "_" but any space following is just removed. You are unable to change the underlying value to be more friendly.

go to the form designer and add your new sections. In my case, I have a couple of additional sections. I have added the incident variable editor to my incident form so I needed to do an extra step. First, I needed to find out the order my Self Service Input section was sitting. To do this, open up your console and type in g_form.getSectionNames(); You can see on my incident form I have 9 sections in total and self-service is sitting in 5.

image

Then you need to open up UI policies and find FormSection_Ctrl_self_service and edit the line 5 - sections[5].style.display = 'block'; Change the number to wherever your self-service section is sitting. Do that for both the true and false conditions.

image

To hide your sections is pretty simple. create your UI Policy and make sure to check run Scripts. In your true/false sections add your code:

True:function onCondition() {g_form.setSectionDisplay('microphone', true);g_form.setSectionDisplay('call_quality', true);}False:function onCondition() { g_form.setSectionDisplay('microphone', false);g_form.setSectionDisplay('call_quality', false);

}

View original source

https://www.servicenow.com/community/developer-articles/how-to-using-ui-policies-to-hide-form-sections/ta-p/2323072