Skip to main content
Participant
Aug 18, 2021 5:07 AM UTC
Answered

Calculate commencement date to an expiry date

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 is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Aug 19, 2021 8:16 AM UTC

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

8 replies

try67
Community Expert
Community Expert
Aug 18, 2021 2:05 PM UTC

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?

Translate
CC717Author
Participant
Aug 18, 2021 10:12 PM UTC

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 

Translate
try67
Community Expert
Community Expert
Aug 18, 2021 10:20 PM UTC

What are the names of the fields involved?

Translate