Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Validation for Start Date and End Date using UI Policy Scripting

Bobdevd
Mega Contributor

Hi guys, I'm looking into validating my Start Date and End Date in my form using UI Policy Scripting. The scenario is as follows:

 

1) Column Label: Start Date 

    Field Name: start_date

 

2) Column Label: End Date

     Field Name: end_date

 

3) Want to validate if End Date is earlier than the Start Date?

 

4) Under the "When to apply" section, my condition is: End Date is less than 1 Days before Start Date

 

5) In the script section

     Execute if true:  

     function onCondition()

     {

             g_form.showFieldMsg('end_date', 'End Date cannot be before start date!', 'error');

     }

 

     Execute if false:  

     function onCondition()

     {

             g_form.hideFieldMsg('end_date',);

     }

 

After I did the above, by right it should display an error message of 'End Date cannot be before the Start Date!' if the End Date selected is before the Start Date.

 

But what I have seen is that when I selected the End Date is earlier than the Start Date, the error message did not appear, and it only appears when both the Start Date and the End Date is the same. This should not be the case based on the condition defined in 4) above.

I have tried troubleshooting it but still did not able to solve the issue. Please enlighten me on this, thanks!

 

0 REPLIES 0