Hide variable through onchange client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2019 07:09 AM
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2019 07:11 AM
Best way is to use UI policy, it will revert the changes if value changes.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2019 07:15 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2019 07:20 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2019 12:53 AM
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