- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2017 08:30 AM
So, I have set up a client script to remove options depending upon option set on a dependant field BUT after refreshing form the options selected are refreshing, the clearOptions function is running again
I'm sure this is simple but I can new to client scripts.
Here is my script, any advice is welcome. BTW this is on a scoped application.:
function onChange(control, oldValue, newValue, isLoading) {
if (newValue === 'In Store'){
g_form.clearOptions('complaint_sub_category');
g_form.setMandatory('complaint_sub_category',false);
g_form.setVisible('complaint_sub_category',false);
}
}
I suspect I need to state isLoading is false, i tried but obviously got it wrong
Thanks in advance
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2017 08:33 AM
If you want the onChange client script to NOT run on loading (as an onLoad script does) Add these lines just inside the function.
if (isLoading)
return;
Can you help me understand why you want to clear all the options in the case of the In Store value? This shouldn't be necessary if you are hiding it anyway. Perhaps just use a g_form.setValue('fieldname', ''); to set it to empty instead.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2017 08:33 AM
If you want the onChange client script to NOT run on loading (as an onLoad script does) Add these lines just inside the function.
if (isLoading)
return;
Can you help me understand why you want to clear all the options in the case of the In Store value? This shouldn't be necessary if you are hiding it anyway. Perhaps just use a g_form.setValue('fieldname', ''); to set it to empty instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2017 12:46 AM
top man
on a previous version i had:
if (isLoading)
{}
which did not work, so I removed it, so close yet so far.
Thanks ctomasi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2017 08:36 AM
can you put clearOptions before if loop and check also put alerts and check.
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2017 08:37 AM
Hi Dave,
An onChange script also runs onLoad.
This can easily be resolved by adding the following 2 lines:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading)
return;
if (newValue === 'In Store'){
g_form.clearOptions('complaint_sub_category');
g_form.setMandatory('complaint_sub_category',false);
g_form.setVisible('complaint_sub_category',false);
}
}
Thanks Robbie
Please mark helpful and/or correct by clicking on the post link (client script is setting drop down options working perfectly BUT onload it is removing options again ) to help close out open questions and aid others with the same or similar question.