Hi community
This forum is amazing at assisting young developers to improve. Thank you!
I have a need to add days to a date in combination with a 3rd option field selection.
Here are the conditions:
Option Field = Duration (2 Weeks / 1 Month / 2 Months)
StartDate Field = Date Only (manual entry)
EndDate Field = Date Only (javascript needing to calculate result)
I have tried multiple options to get this right without success. Below is the final 2 scripts I have been working on.
function SetEndDate(executionContext) {
//Get the context of the form
var formContext = executionContext.getFormContext();
//The logical name of the field of interest
var Duration = "new_duration";
var StartDate = "new_startdate";
var EndDate = "new_enddate";
//Declare the other variables as needed
var StartDateValue = "new_startdate";
var EndDateValue = new Date();
var TwoWeeks = 14;
var OneMonth = 30;
var TwoMonths = 60;
var DateTimeConverter = 24 * 60 * 60 * 1000;
if(Duration.getValue() == 100000000) {
//Set the EndDate to 14 days after the StartDate
EndDateValue.setTime(StartDateValue.getTime() (TwoWeeks * DateTimeConverter));
// Set the value of the field
EndDate.setValue(EndDateValue);
}
else if(Duration.getValue() == 100000001) {
//Set the EndDate to 30 days after the StartDate
EndDateValue.setTime(StartDateValue.getTime() (OneMonth * DateTimeConverter));
// Set the value of the field
EndDate.setValue(EndDateValue);
}
else if(Duration.getValue() == 100000002) {
//Set the EndDate to 60 days after the StartDate
EndDateValue.setTime(StartDateValue.getTime() (TwoMonths * DateTimeConverter));
// Set the value of the field
EndDate.setValue(EndDateValue);
}
else {
}
}function SetEndDate(executionContext) {
//Get the context of the form
var formContext = executionContext.getFormContext();
//The logical name of the field of interest
var Duration = "new_duration";
var StartDate = "new_startdate";
var EndDate = "new_enddate";
//Declare the other variables as needed
var StartDateValue = "new_startdate";
var EndDateValue = new Date();
var TwoWeeks = 14;
var OneMonth = 30;
var TwoMonths = 60;
if(Duration.getValue() == 100000000) {
//Set the EndDate to 14 days after the StartDate
EndDateValue.setTime(StartDateValue.getTime() TwoWeeks);
// Set the value of the field
EndDate.setValue(EndDateValue);
}
else if(Duration.getValue() == 100000001) {
//Set the EndDate to 30 days after the StartDate
EndDateValue.setTime(StartDateValue.getTime() OneMonth);
// Set the value of the field
EndDate.setValue(EndDateValue);
}
else if(Duration.getValue() == 100000002) {
//Set the EndDate to 60 days after the StartDate
EndDateValue.setTime(StartDateValue.getTime() TwoMonths);
// Set the value of the field
EndDate.setValue(EndDateValue);
}
else {
}
}Any assistance is greatly appreciated.