Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Hide form container based on field value?

Kiran_25
Tera Expert

Hi I am trying to hide a form container (I could be wrong, but I'm sure that's what its called 😁) based on the the value of the task type field. I was thinking of scripting this however I am able to see it on form designer & form builder but can't find any labels or sys IDs for it. How can i achieve this? Thanks.

 

thrsdy1512_0-1745935545043.png

 

1 ACCEPTED SOLUTION

@Kiran_25 

are you comparing the correct field and correct value?

you should compare choice value and not choice label

function onLoad() {
    var change_task_Type = g_form.getValue('change_task_type');
    if (change_task_Type == 'review') {
        g_form.setSectionDisplay('closure_information', false);
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Kieran Anson
Kilo Patron
Hi,
The following will work
g_form.setSectionDisplay('closure_information', false);

 

If you're unsure on the section name, as it might differ, you can use your browser's devtools and the following script

g_tabs2Sections.tabNames

Thanks Kieran, I'm guessing this should be done as a onLoad client script?

You can do this in either an onLoad client script or the script section of a UI policy. I tend to go with UI policies for anything that show/hides fields

Ankur Bawiskar
Tera Patron
Tera Patron

@Kiran_25 

it's called form section

ServiceNow provides this OOTB method to show/hide form section

The function accepts form section name separated by underscore and lower case

i.e. Closure Information -> closure_information

g_form.setSectionDisplay('closure_information', false);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader