Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

Auto calculate dates and populate fields

New Here ,
Sep 22, 2023 Sep 22, 2023

I am creating a form the give dates  they can use security authentication codes given to them

There are  28 day codes, 60 week codes and 5 year codes.  I created a drop down box 

with their selection (i.e., 28, 60, etc).  Is there a way to create separate fields that give

the start and end date of each type selected?

TOPICS
JavaScript
568
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2023 Sep 22, 2023

The end date can be calculated based on the start date and that period, but what is the start date? The current date? A date the user enters? Something else?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 22, 2023 Sep 22, 2023

Date entered by the user

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2023 Sep 22, 2023
LATEST

Then you can use something like this as the custom calculation script of the end date field (adjust the field names, options and date format as needed):

 

var startDate = this.getField("StartDate").valueAsString;
var term = this.getField("Term").valueAsString;
if (startDate=="") event.value = "";
else {
	var d = util.scand("mm/dd/yyyy", startDate);
	if (term=="28 Days") d.setDate(d.getDate()+28);
	else if (term=="60 Weeks") d.setDate(d.getDate()+(60*7));
	else if (term=="5 Years") d.setFullYear(d.getFullYear()+5);
	event.value = util.printd("mm/dd/yyyy", d);
}

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines