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

Hi Ankur 

would this be a client script? 

@Kiran_25 

that's correct it should be a client script either onLoad or onChange as per your requirement.

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

I have tried it but havent been able to get it to work using a onLoad client script:

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

@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