What is the best way to validate a date field?

Tyler Michals
Kilo Guru

We have a custom date field where we do not want anyone to specify a date at the end of the month - day 29, 30, and 31.

I tried a business rule and an "on change" client script, but i guess my coding wasn't good enough. Can anyone help?

 

Thanks!

Tyler

1 ACCEPTED SOLUTION

Try this:

(function calculatedFieldValue(current) {

var date = new GlideDateTime(current.u_bill_cycle_date);


return date.getDayOfMonthLocalTime(); // return the calculated value

})(current);


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

View solution in original post

4 REPLIES 4

Scott Jordheim
Giga Guru

If it is in a Catalog Item, using a Catalog UI Policy typically works pretty well, with little impact on the instance. I haven't really investigated using something like this outside of a catalog item, but it should be similar. I also have it running On Load, only on Catalog Item View, and not Reverse if False.

Issue: I don't want anyone to select a date before 4 weeks from now.

Catalog Condition:

  • myvariable relative before 28 days from now

find_real_file.png

Tyler Michals
Kilo Guru

Hey Scott,

 

Thanks for the reply, but we are looking to validate the day of the date chosen. The day itself cannot be the 29th, 30th, or 31st.

 

I found this code .getDayOfMonth() but have not been able to successfully apply it

Tyler Michals
Kilo Guru

We had an idea to create a custom field called "Day of Month". This field will be calculated from the other custom date field. Then we can set-up business rules and/or reports based on that field's value. Only problem is that we are having trouble auto calculating the "Day of the Month" field. Below is a version of the script I have been trying to use. Can anyone help me accomplish this?

 

(function calculatedFieldValue(current) {
var billDate = u_bill_cycle_date;
// Add your code here
return billDate.getDayOfMonthLocalTime(); // return the calculated value

})(current);

Try this:

(function calculatedFieldValue(current) {

var date = new GlideDateTime(current.u_bill_cycle_date);


return date.getDayOfMonthLocalTime(); // return the calculated value

})(current);


Please mark my response as correct and helpful if it helped solved your question.
-Thanks