client script is setting drop down options working perfectly BUT onload it is removing options again

dave_edgar
Mega Guru

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

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

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.


View solution in original post

6 REPLIES 6

Thanks same awesome advise as legend Chuck but now I have another issue in the same area.  



Creating records from a record producer is removing the chosen option from the record producer.



The two list match exactly so unsure why this is occurring.  


ignore that, forgot to map the field. face|palm