Hide form sections when no fields present

ebaileyybs
Tera Expert

Hi, I have created a UI policy/actions to hide certain fields under form sections when a particular category of record is selected.

Even though there aren't any fields - the form sections are still showing.

Please can you advise how these can be hidden when the UI policy removes the fields. I have no knowledge of scripting so help on this would be greatly appreciated!

Sections/tabs showing even though fields are hidden:

find_real_file.png

Form sections

find_real_file.png

Thanks in anticipation!

Emma

5 REPLIES 5

Mihir Mohanta
Kilo Sage

Instead of hiding all fields in a section ,you can directly hide/display entire section using below script



var sections = g_form.getSections();


g_form.setSectionDisplay(sections[i], true);


g_form.setSectionDisplay(sections[i], false);




//in place of i provide your section number like 1 or 2 etc




Thanks,


Mihir


Thanks for this.



What type of script would this be and how would I set the condition please?



Emma


You can also use getSectionNames function also for this and directly put section names also..


13.3 getSectionNames


array getSectionNames()


Returns all section names, whether visible or not, in an array.
Returns:
array - the segment names.
GlideForm (g form) - ServiceNow Wiki

Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa


Here is an on change client script that will hiding a section when state is 2



function onChange(control, oldValue, newValue, isLoading) {


    //this example was run on a form divided into sections (Change form)


    // and hid a section when the "state" field was changed


var sections = g_form.getSections();


if(isLoading){


if(g_form.getValue('state')=='2')


  g_form.setSectionDisplay(sections[1], false);


}


 


    if (newValue == '2') {


          g_form.setSectionDisplay(sections[1], false);


    } else {


          g_form.setSectionDisplay(sections[1], true);


    }


}