Why setDisplay() method is not working?

Ankita28
Giga Contributor

The below client script is for service portal in which setDisplay() method is not working.

Could anyone please help?

find_real_file.png

find_real_file.png

Thanks,

Ankita

11 REPLIES 11

@Ankita let me know if this works for you 🙂

function onLoad(){
    if(g_form.getValue('u_source') == 'others'){
        alert('true');
        g_form.setVisible('u_new_source', true);
    }
    else{
        alert('false');
        g_form.setMandatory('u_new_source', true);
        g_form.setVisible('u_new_source', false);

    }
}

Ankita28
Giga Contributor

Hi Willem,

Still it's not working.

Thanks,

Ankita

You want to show the field only if u_source is others right?

You should use this:

function onLoad(){
    if(g_form.getValue('u_source') == 'others'){
        alert('true');
        g_form.setMandatory('u_new_source', true);
        g_form.setVisible('u_new_source', true);
    }
    else{
        alert('false');
        g_form.setMandatory('u_new_source', false);
        g_form.setVisible('u_new_source', false);

    }
}

 

You cannot set a mandatory field to not be visible. So you have to make it not mandatory first.

Hi Ankita,

The script you have added in question is right just few changes required there.

Updated script.

 

function onLoad(){
if(g_form.getValue('u_source') == 'others'){
alert('true');
g_form.setVisible('u_new_source', true);
}
else{
alert('false');
g_form.setMandatory('u_new_source', false);
g_form.setVisible('u_new_source', false);

}
}

 

Note - changes are in bold.

Thanks,

Dhananjay.

Dhananjay Pawar
Kilo Sage

Hi,

In addition to above, You can use

g_form.setVisible('u_source',true);

g_form.setVisible('u_source',false);

Thanks,

Dhananjay.