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

Calculate commencement date to an expiry date

Community Beginner ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

Hi All,


I am trying to build a form as per below image.

 

I have a commencement date which is a drop down date selected with dd-mmm-yyyy format.

 

I want the drop down selectors for date & month in Initial Term to update the drop down date selector in Initial Term if this is possible.


If not possible what is the best way to go about this to update the commencement date from a selected number of years/months? 

 

defaults12rwjgmjne8_0-1629262905128.png

 

TOPICS
Acrobat SDK and JavaScript , Windows

Views

112

Likes

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Aug 19, 2021 Aug 19, 2021

You can use this code as the custom calculation script of the last field:

 

var commDateString = this.getField("Date24_af_date").valueAsString;
if (commDateString=="") event.value = "";
else {
	var yearsToAdd = Number(this.getField("Dropdown1").valueAsString);
	var monthsToAdd = Number(this.getField("Dropdown2").valueAsString);
	var commDate = util.scand("dd-mmm-yyyy", commDateString);
	commDate.setFullYear(commDate.getFullYear()+yearsToAdd);
	commDate.setMonth(commDate.getMonth()+monthsToAdd);
...

Likes

Translate

Translate
Community Expert ,
Aug 18, 2021 Aug 18, 2021

Copy link to clipboard

Copied

So you want to calculate the value of the "Service delivery on" field, based on the Commencement Date and the other two drop-downs for years and months, basically?

Likes

Translate

Translate

Report

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 Beginner ,
Aug 18, 2021 Aug 18, 2021

Copy link to clipboard

Copied

Hi - thanks for your reply & yes that is correct - I have tried to google and go through the community board here regarding using javascript for it but cannot find anything that exactly matches my needs - however happy to be  advised if there is a better way to do this/what is easiest etc. 

 

Thanks 

Likes

Translate

Translate

Report

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 ,
Aug 18, 2021 Aug 18, 2021

Copy link to clipboard

Copied

What are the names of the fields involved?

Likes

Translate

Translate

Report

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 Beginner ,
Aug 18, 2021 Aug 18, 2021

Copy link to clipboard

Copied

Commencement date has a dropdown date selector is called - Date24_af_date
Initial Term first dropdown box for years is called - Dropdown1

Initial Term second dropdown box for months is called - Dropdown2

Initial Term for "Service Delivery On" dropdwon date selector is called - Date27_af_date

Screenshot attached below

CC717_0-1629325399796.png

 

Likes

Translate

Translate

Report

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 ,
Aug 19, 2021 Aug 19, 2021

Copy link to clipboard

Copied

You can use this code as the custom calculation script of the last field:

 

var commDateString = this.getField("Date24_af_date").valueAsString;
if (commDateString=="") event.value = "";
else {
	var yearsToAdd = Number(this.getField("Dropdown1").valueAsString);
	var monthsToAdd = Number(this.getField("Dropdown2").valueAsString);
	var commDate = util.scand("dd-mmm-yyyy", commDateString);
	commDate.setFullYear(commDate.getFullYear()+yearsToAdd);
	commDate.setMonth(commDate.getMonth()+monthsToAdd);
	event.value = util.printd("dd-mmm-yyyy", commDate);
}

Likes

Translate

Translate

Report

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 Beginner ,
Aug 19, 2021 Aug 19, 2021

Copy link to clipboard

Copied

Amazing thank you @try67 that worked perfectly - I just needed to add an } at the end of the code as it was erroring in javascript but besides that works exactly how I needed.

Thanks for taking time out of your day to assist its much appreciated

Likes

Translate

Translate

Report

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 Beginner ,
Aug 19, 2021 Aug 19, 2021

Copy link to clipboard

Copied

Just realised it was my error & not yours as you had the } just at the bottom but I wasn't copying it across.


My apologies - your code was perfect thank you again. 

Likes

Translate

Translate

Report

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 ,
Aug 20, 2021 Aug 20, 2021

Copy link to clipboard

Copied

LATEST

Glad to hear it!

Likes

Translate

Translate

Report

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