Date comparsion and validation within Catalog Items.

peterwigham
Kilo Expert

Hi guys,

 

I'm hoping someone can help me with this as I've been hitting my head against a brick wall all day.

 

I have a Catalog Item with start and end date variables (sDate and endD), both of which are Date type variables. What we need is a validation to check that the sDate value is a date in the future and that endD value to check to ensure it is later (in the future) than the sDate value that's entered.

 

I've looked within the wiki and Community and there appear to be lots of information on this however nothing I've tried seems to have worked. I've tried simple Catalog Client Scripts to perform this but they have not worked. I've tried to then use Script Includes with Client Scripts but these do not seem to work properly for me either. The issues I've had are:

 

- Populating the the sDate with a value forces the alert to display where the date is in the past of the future. If date is TODAY then it seems to show NO alert.

- Alert displaying when populating the endD variable whether the value is later in the sDate variable value or not.

 

In an attempt to debug I thought that there may be an issue with obtaining the current date and so I used a Script Include to get this and used it as a variable to populate the start date. In some cases this worked but in others the value merely populated as 'null'.

 

Some of the articles I've checked (and used) but that have not resolved this issue are:

 

Date Validation script needed for Catalog Item date variable.

Comparing Client Dates

Validate a date via a client script

 

Any help on this would be hugely appreciated.

 

Thanks in advance,

PW

1 ACCEPTED SOLUTION

KHDouglas
Giga Expert

Hi Peter,



This can be done using 2 onChange client scripts, both in attached txt doc.



Karl


View solution in original post

9 REPLIES 9

Smart, it was very helpful, Thank u so much



i used these and no matter what i put for start date field, it pops the message even if i do put  a date in the future. ??

These code snippets are very helpful ... IDK anyone that LIKES working with dates!! 

 

I see you have the MaxDiff variable but do not use it in the IF/IFESLE section ... 

 

 

jmrece
Kilo Contributor

Hi Karl,


The date scripts are fine. on change of which field you implemented this.



for example you created change request today and the planned start date selected greater(suppose 15th) than current date(suppose 14th). Later 5 days you came and trying to change planned start date to 16th, but current date is 19th. The validation will fire and won't allow us to select desired date in planned start date for change implementation. My doubt here is current date will dynamically change and we can't compare with current date always. We should restrict this validation only if the record is "new record" or any other condition


harikrish_v
Mega Guru

Hi Peter,



I am not sure if you have seen the below post. It explains how you can create date/time utilities that can be used at client side. You can create a script include which does all the work and then make an async glideajax call to invoke the utility. It is re-usable and also pretty standard, so margin for erroneous result is very less.



Client Script Date/Time Functions



Hope this helps



Thanks & Regards,


Hari