Skip to main content
Participant
January 20, 2023
Answered

Autofill expiration date to last day of the year based off of another date field

  • January 20, 2023
  • 1 reply
  • 790 views

I need to set up an auto-fill date field that is the last day of the year based off of another date field.

Example: "Requested Start Date" field is 1/23/23, I need the "Expiration Date" field to auto-fill as 12/31 of the same year as the Requested Start Date Field (so it would be 12/31/23). If someone selects 2/2/24 as start date, I need the expiration date field to be 12/31/24, etc. The expiration date always needs to be the last day of the year of the start date field.

 

Can anyone help me with the javascript code to do this? I am struggling to get it to work.

This topic has been closed for replies.
Correct answer Nesa Nurani

Use this as validation script of "Requested Start Date" field:

var date = util.scand("mm/dd/yy", event.value);
if(event.value == "")
this.getField("Expiration Date").value = "";
else{
var year = date.getFullYear()+1;
var str = year.toString();
this.getField("Expiration Date").value = "12/31/"+str.slice(2,4);}

 

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
January 20, 2023

Use this as validation script of "Requested Start Date" field:

var date = util.scand("mm/dd/yy", event.value);
if(event.value == "")
this.getField("Expiration Date").value = "";
else{
var year = date.getFullYear()+1;
var str = year.toString();
this.getField("Expiration Date").value = "12/31/"+str.slice(2,4);}

 

Participant
January 20, 2023

Well you are just fantastic! That worked beautifully. Thank you so much! 🙂