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

compare two date fields

cray
Kilo Contributor

i have two date fields

1)start date

2)end date

if start date is greater than end date,abort the form from submission

please help me with the businees rule script..

12 REPLIES 12

prajaktanaik
Giga Expert

Hi Prashanth,



Use a client script with below code:



var start_d = getDateFromFormat(g_form.getValue('start_date'), g_user_date_time_format);


                      var end_d = getDateFromFormat(g_form.getValue('end_date'), g_user_date_time_format);


                      if (start_d > end_d) {


                            alert("End Date must not be before Start Date");


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


              return false;


                      }    


Please help me 

https://community.servicenow.com/community?id=community_question&sys_id=aa6f9ebb1b23d810d2ccea89bd4bcbef

lorisd_avanzo
ServiceNow Employee
ServiceNow Employee

GlideDateTime and the compareTo() function is probably what you are looking for.


Please refer to this wiki article where you can also find some example code to use in your Business Rule script.


Note, being usable in a Business Rule, that code will be working on the server side and you won't be able to use the same code in client side, e.g. in Client Scripts.



I hope it helps.



Regards,


Loris


lorisd_avanzo
ServiceNow Employee
ServiceNow Employee

I also found another wiki article which seems to do what you are looking for, including the aborting action (all done from a Business Rule).


Please see Comparing Two Date fields.



Regards,


Loris D'Avanzo