Client script getOptions() issue (field choices not resetting when changing onChange field)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
I have create an onChange client script on 'type' field with the logic to display choices in choice field 'suspension_reason'.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var internal1 = g_scratchpad.internalreasons;
var external1 = g_scratchpad.externalreasons;
var type1 = g_form.getValue('type');
internal1 = internal1.split(',');
external1 = external1.split(',');
// Add the appropriate options based on the selected type
if (type1 == 'Internal Suspend') {
g_form.setValue('your_choice_field', '');
for (var j1 = 0; j1 < external1.length; j1++) {
g_form.removeOption('suspension_reason', external1[j1]);
}
for (var k1 = 0; k1 < internal1.length; k1++) {
g_form.addOption('suspension_reason', internal1[k1]);
}
} else if (type1 == 'External Suspend') {
g_form.setValue('your_choice_field', '');
for (var l1 = 0; l1 < internal1.length; l1++) {
g_form.removeOption('suspension_reason', internal1[l1]);
}
for (var m1 = 0; m1 < external1.length; m1++) {
g_form.addOption('suspension_reason', external1[m1]);
}
}
g_form.clearValue('suspension_reason');
}
Here,
When I select type as Internal Suspend, the choices in suspension_reason fields show correctly. But when I change the type from Internal Suspend to External Suspend, the choices show 'None'.
Same happens vice versa, when I select External Suspend, the choices in suspension_reason show properly, but when I reselect the type field as Internal Suspend, the choices show 'None'.
What changes can I make to make it work as expected.
I have tried adding g_form.clearOptions('suspension_reason'); before if/else if conditions doesnt work.
Please drop if you guys have any suggestions to make.