Skip to main content
Participant
August 18, 2021
Answered

Calculate commencement date to an expiry date

  • August 18, 2021
  • 1 reply
  • 1421 views

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? 

 

 

This topic has been closed for replies.
Correct answer try67

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

 


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);
}

1 reply

try67
Community Expert
Community Expert
August 18, 2021

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?

CC717Author
Participant
August 18, 2021

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 

try67
Community Expert
Community Expert
August 18, 2021

What are the names of the fields involved?