Hide variable through onchange client script

salu
Mega Guru

Hello All,

 

I want to hide variable when selecting the request.I have written below client script but its not hiding if I select the value again

 

For example,If I select Add the application new application will come but when i select retire application the field is not getting hided.Please help

find_real_file.png

 

find_real_file.png

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {

return;

}
clearfields();
if (newValue == 'Add the Application') {

g_form.setMandatory('u_add_appl', true);
g_form.setMandatory('u_assigned_to', true);
g_form.setMandatory('u_assignment_group', true);

g_form.setDisplay('u_add_appl',true);
g_form.setDisplay('u_assigned_to',true);
g_form.setDisplay('u_assignment_group',true);

g_form.setDisplay('u_modify_application',false);
g_form.setDisplay('u_application',false);


}
if (newValue == 'Modify the Application') {

g_form.setMandatory('u_modify_application', true);
g_form.setMandatory('u_assigned_to', true);
g_form.setMandatory('u_assignment_group', true);

g_form.setDisplay('u_modify_application',true);
g_form.setDisplay('u_assigned_to',true);
g_form.setDisplay('u_assignment_group',true);

g_form.setDisplay('u_add_appl',false);
g_form.setDisplay('u_application',false);


}
if (newValue == 'Retire the Application') {

g_form.setMandatory('u_application', true);
g_form.setMandatory('u_assigned_to', true);
g_form.setMandatory('u_assignment_group', true);

g_form.setDisplay('u_application',true);
g_form.setDisplay('u_assigned_to',true);
g_form.setDisplay('u_assigned_to',true);

g_form.setDisplay('u_add_appl',false);
g_form.setDisplay('u_modify_application',false);


}
//opriate comment here, and begin script below

}

function clearfields()
{

g_form.setValue('u_add_appl',"");
g_form.setValue('u_application',"");
g_form.setValue('u_assigned_to',"");
g_form.setValue('u_assignment_group',"");
g_form.setValue('u_modify_application',"");

} //Type appr

5 REPLIES 5

Shashikant Yada
Tera Guru

Best way is to use UI policy, it will revert the changes if value changes.

VigneshMC
Mega Sage

As shashikant suggested, you should try using ui policy.

If you still want to use client script, then the reason why the field is not getting hidden is because its mandatory. Make non-mandatory before hiding(do it for all fields you want to hide).

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {

return;

}
clearfields();
if (newValue == 'Add the Application') {

g_form.setMandatory('u_add_appl', true);
g_form.setMandatory('u_assigned_to', true);
g_form.setMandatory('u_assignment_group', true);

g_form.setDisplay('u_add_appl',true);
g_form.setDisplay('u_assigned_to',true);
g_form.setDisplay('u_assignment_group',true);

g_form.setDisplay('u_modify_application',false);
g_form.setDisplay('u_application',false);


}
if (newValue == 'Modify the Application') {

g_form.setMandatory('u_modify_application', true);
g_form.setMandatory('u_assigned_to', true);
g_form.setMandatory('u_assignment_group', true);

g_form.setDisplay('u_modify_application',true);
g_form.setDisplay('u_assigned_to',true);
g_form.setDisplay('u_assignment_group',true);

g_form.setDisplay('u_add_appl',false);
g_form.setDisplay('u_application',false);


}
if (newValue == 'Retire the Application') {
g_form.setMandatory('u_add_appl', false);
g_form.setMandatory('u_application', true);
g_form.setMandatory('u_assigned_to', true);
g_form.setMandatory('u_assignment_group', true);

g_form.setDisplay('u_application',true);
g_form.setDisplay('u_assigned_to',true);
g_form.setDisplay('u_assigned_to',true);

g_form.setDisplay('u_add_appl',false);
g_form.setDisplay('u_modify_application',false);


}
//opriate comment here, and begin script below

}

function clearfields()
{

g_form.setValue('u_add_appl',"");
g_form.setValue('u_application',"");
g_form.setValue('u_assigned_to',"");
g_form.setValue('u_assignment_group',"");
g_form.setValue('u_modify_application',"");

} //Type appr

Brian Lancaster
Tera Sage

I'm not seeing any issues with a script but I'm wondering why you are not using standard UI Policies instead of a script.

 

Just another thought.  If you are setting that field mandatory in one section.  When you set visible to false you also have to set mandatory to false.

You said it.I was wondering why its not working.

 

We have to make mandatory false when display false.Its working now 🙂

 

Thank you very much for the help.

 

I have used UI policy but there are three UI policy writter and its not working properly then thought of writing one client script