- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2022 12:04 PM
I am trying to clear hide certain variables when a dropdown option is set to --None--. Below is a example of what I tried.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
if (newValue == '') {
g_form.setDisplay("variable_a", false);
g_form.setMandatory("variable_a", false);
g_form.setDisplay("variable_b", false);
g_form.setMandatory("variable_b", false);
g_form.setDisplay("variable_c", false);
g_form.setMandatory("variable_c", false);
} else if (newValue == "new") {
//clear and hide variable_a and variable_b
g_form.clearValue("variable_a");
g_form.setMandatory("variable_a", false);
g_form.setDisplay("variable_a", false);
g_form.clearValue("variable_b");
g_form.setMandatory("variable_b", false);
g_form.setDisplay("variable_b", false);
// display and make mandatory correct variable
g_form.setDisplay("variable_c", true);
g_form.setMandatory("variable_c", true);
} else if (newValue == "modify") {
//clear and hide variable_c and variable_b
g_form.clearValue("variable_c");
g_form.setMandatory("variable_c", false);
g_form.setDisplay("variable_c", false);
g_form.clearValue("variable_b");
g_form.setMandatory("variable_b", false);
g_form.setDisplay("variable_b", false);
// display and make mandatory correct variable
g_form.setDisplay("variable_a", true);
g_form.setMandatory("variable_a", true);
} else {
//clear and hide variable_c and variable_a
g_form.clearValue("variable_c");
g_form.setMandatory("variable_c", false);
g_form.setDisplay("variable_c", false);
g_form.clearValue("variable_a");
g_form.setMandatory("variable_a", false);
g_form.setDisplay("variable_a", false);
// display and make mandatory correct variable
g_form.setDisplay("variable_b", true);
g_form.setMandatory("variable_b", true);
}
}
The rest of the code works as intended and I am not even sure if this is the best way to handle what I'm trying to do so any help or feedback would be greatly appreciated.
Thanks in advance!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2022 03:50 PM
Hi Tgutierrez,
The onChange script isn't getting executed because of the following if condition on top.
if (isLoading || newValue == '') { // skip on load and value is empty.
return;
}
Remove the "newValue == ''" check
if (isLoading) { // skip on load only
return;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2022 12:20 PM
Best way would be to use ui policies, you need to make multiple ones, but that would be most efficient way.
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2022 03:50 PM
Hi Tgutierrez,
The onChange script isn't getting executed because of the following if condition on top.
if (isLoading || newValue == '') { // skip on load and value is empty.
return;
}
Remove the "newValue == ''" check
if (isLoading) { // skip on load only
return;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2022 04:11 PM
There's also a need to change the order of setDisplay() and setMandatory() because mandatory fields can not be hidden.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
//Type appropriate comment here, and begin script below
if (newValue == '') {
g_form.setMandatory("variable_a", false);
g_form.setDisplay("variable_a", false);
g_form.setMandatory("variable_b", false);
g_form.setDisplay("variable_b", false);
g_form.setMandatory("variable_c", false);
g_form.setDisplay("variable_c", false);
} else if (newValue == "new") {
//clear and hide variable_a and variable_b
g_form.clearValue("variable_a");
g_form.setMandatory("variable_a", false);
g_form.setDisplay("variable_a", false);
g_form.clearValue("variable_b");
g_form.setMandatory("variable_b", false);
g_form.setDisplay("variable_b", false);
// display and make mandatory correct variable
g_form.setDisplay("variable_c", true);
g_form.setMandatory("variable_c", true);
} else if (newValue == "modify") {
//clear and hide variable_c and variable_b
g_form.clearValue("variable_c");
g_form.setMandatory("variable_c", false);
g_form.setDisplay("variable_c", false);
g_form.clearValue("variable_b");
g_form.setMandatory("variable_b", false);
g_form.setDisplay("variable_b", false);
// display and make mandatory correct variable
g_form.setDisplay("variable_a", true);
g_form.setMandatory("variable_a", true);
} else {
//clear and hide variable_c and variable_a
g_form.clearValue("variable_c");
g_form.setMandatory("variable_c", false);
g_form.setDisplay("variable_c", false);
g_form.clearValue("variable_a");
g_form.setMandatory("variable_a", false);
g_form.setDisplay("variable_a", false);
// display and make mandatory correct variable
g_form.setDisplay("variable_b", true);
g_form.setMandatory("variable_b", true);
}
}
Execution result
case 1: New
case 2: Modify
case 3: Else
case 4: None