How do i hide sub sections in a form?

ChuanYanF
Tera Guru

Dear experts,

 

I tried to hide a form section but it did not went well, may I know why. I followed a solution accepted post, but it still not working on my side. I tried to hide the tab 'Applicability and Categorisation' but it did not hide for some reason. Please advise.  I tried changing the code name from upper case, lower case and even added _ to it but all is not working for now.

function onLoad() {
    var appliesTo = g_form.getValue('applies_to');  
    var engagementValue = 'engagement';  // replace with actual value stored in applies_to

    if (appliesTo === engagementValue) {
        g_form.setSectionDisplay('applicability_and_categorisation', false);  // hide section
    } else {
        g_form.setSectionDisplay('applicability_and_categorisation', true);   // show section
    }
}

ChuanYanF_0-1756367735037.png

 

2 REPLIES 2

Rafael Batistot
Kilo Patron

Hi @ChuanYanF 

 

This post might help you 

 

https://www.servicenow.com/community/developer-articles/servicenow-form-section-hide-show-servicenow...

If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.

Ankur Bawiskar
Tera Patron
Tera Patron

@ChuanYanF 

are you sure you are comparing the correct value in the IF?

what type of field is applies_to

try adding alert and see

function onLoad() {
    var appliesTo = g_form.getValue('applies_to');
    var engagementValue = 'engagement'; // replace with actual value stored in applies_to
    alert(appliesTo);
    if (appliesTo === engagementValue) {
        g_form.setSectionDisplay('applicability_and_categorisation', false); // hide section
    } else {
        g_form.setSectionDisplay('applicability_and_categorisation', true); // show section
    }
}

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