How to check if a field on the form is visible in Client Script?

Ashish70
Giga Contributor

I have a field on a form which I want to verify as being hidden/ empty. The field would be hidden if it is empty as that part is already built in. I want to find out if the field is visible or if the field is empty on the form in a client script. Please help. Thanks.

1 ACCEPTED SOLUTION

JayGervais
Kilo Sage

You could do a check like this.

if (g_form.isVisible('field') || g_form.getValue('field') != '') {

  // check if the field is visible or has a value

}

View solution in original post

7 REPLIES 7

Rebecca3
Tera Guru

I had an issue that was preventing User's from changing their view because I had a client script checking the length of a field on submit and the field wasn't on the form.

ServiceNow recommended the code below - looks like .hasField() has replaced .isVisible()

It returns true if the field is on the form, and returns empty if its not.

if (!g_form.hasField('short_description')) {
    return true;
}

Community Alums
Not applicable
You could check with that:

 

if(g_form.isVisible(g_form.getGlideUIElement("your field")== true){

 

}

 

priyanka garad
Giga Expert

hi,

    It will return true if the field is visible.

    g_form. isVisible("fieldName");