The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Best practice: UI Policy vs Client Script @ date/time fields

divvi_vamsi
Mega Expert

I am working on one requirement, which is to display/select only current and future dates. So when did some research on this over the community had a couple of questions:

  1. Lot of posts defaulted to client scripts

                  Saw very few or negligible replies mentioning on UI policies (believe this is the best practice)

                  Which of them is a valid best practice? and any limitations for any of these approach?

        2. And also, I want to apply this condition to both start and end dates, so in my case i defined 2 ui policies for each case as if the condition is not met it clears only that specific field. But i see           it doesn't work the way expected. Few times it displays the alert configured and sometimes it just accepts the values. So wondering if any issue due to Order field.

        3. Finally, I did find various ways to abort the operation or clear the values or replace the field with empty string, as below:

                            current.setAbortAction(true);

                            g_form.clearValue('u_date');

                            g_form.setValue('u_date','');

                  Which of these serves best for the purpose?

Thanks

Divya

2 REPLIES 2

Jaspal Singh
Mega Patron
Mega Patron

Hi Divya,



Kindly find my comments in red.



  1. Lot of posts defaulted to client scripts

                  Saw very few or negligible replies mentioning on UI policies (believe this is the best practice)



                  Which of them is a valid best practice? and any limitations for any of these approach?


Both are good & depends on preference. UI Policy is preferred as it does not involve much scripting however, it executes after client script. Client script provides a provision to validation submission as well which UI policy doesn't.




        2. And also, I want to apply this condition to both start and end dates, so in my case i defined 2 ui policies for each case as if the condition is not met it clears only that specific field. But i see           it doesn't work the way expected. Few times it displays the alert configured and sometimes it just accepts the values. So wondering if any issue due to Order field.


Use Onchange Client script instead of UI Policy   & it should work well.



        3. Finally, I did find various ways to abort the operation or clear the values or replace the field with empty string, as below:


                            current.setAbortAction(true); -- Works in Business rule not Client script.


                            g_form.clearValue('u_date'); -- clears field value used in Client script


                            g_form.setValue('u_date',''); -- clears field value used in Client script


Hi Jaspal,



Thanks for the suggestions, My comments in Bold,



Kindly find my comments in red.



  1. Lot of posts defaulted to client scripts

                  Saw very few or negligible replies mentioning on UI policies (believe this is the best practice)



                  Which of them is a valid best practice? and any limitations for any of these approach?


Both are good & depends on preference. UI Policy is preferred as it does not involve much scripting however, it executes after client script. Client script provides a provision to validation submission as well which UI policy doesn't.


But we usually hear that avoiding client scripts is a better option or best practice right, does that not hold good for this?



        2. And also, I want to apply this condition to both start and end dates, so in my case i defined 2 ui policies for each case as if the condition is not met it clears only that specific field. But i see           it doesn't work the way expected. Few times it displays the alert configured and sometimes it just accepts the values. So wondering if any issue due to Order field.


Use Onchange Client script instead of UI Policy   & it should work well. --> Any specific reason why UI Policy didn't work the way as expected?



        3. Finally, I did find various ways to abort the operation or clear the values or replace the field with empty string, as below:


                            current.setAbortAction(true); -- Works in Business rule not Client script. -->How about using this in UI Policy script?


                            g_form.clearValue('u_date'); -- clears field value used in Client script


                            g_form.setValue('u_date',''); -- clears field value used in Client script