Skip to main content
Inspiring
April 17, 2022
Answered

How to auto-populate fields based on entry in another field...

  • April 17, 2022
  • 1 reply
  • 1247 views

Hi!

 

I have a field for "Week Ending Date" and then I have individual fields for each date of that week.

 

I'd like those individual date fields to auto-populate the correct date when the "Week Ending Date" field is filled in.

 

Is that possible?

 

Thank you so much!

This topic has been closed for replies.
Correct answer try67

Yes, this is possible using a script.

Here's the basic code to do it (to be used as the calculation script for the field that needs to show the day before that date, for example):

 

var s = this.getField("WeekEndingDate").valueAsString;
if (s=="") event.value = "";
else {
	var d = util.scand("mm/dd/yyyy", s);
	d.setDate(d.getDate()-1);
	event.value = util.printd("mm/dd/yyyy", d);
}

1 reply

try67
try67Correct answer
Community Expert
April 17, 2022

Yes, this is possible using a script.

Here's the basic code to do it (to be used as the calculation script for the field that needs to show the day before that date, for example):

 

var s = this.getField("WeekEndingDate").valueAsString;
if (s=="") event.value = "";
else {
	var d = util.scand("mm/dd/yyyy", s);
	d.setDate(d.getDate()-1);
	event.value = util.printd("mm/dd/yyyy", d);
}
Inspiring
April 18, 2022

@try67 

Thank you!! You are amazing!! 🙂

 

By reading and following through your script I even managed to set it so that it displays only the date "dd" in the individual fields.

 

Thank you again so much!!

 

Have a great day!

try67
Community Expert
April 18, 2022

Great, and you're very welcome!