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?
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);
...
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?
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
Copy link to clipboard
Copied
What are the names of the fields involved?
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
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);
}
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
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.
Copy link to clipboard
Copied
Glad to hear it!