Hi.
this is what I entered in the custom calculation script to the Form that I am making:
// DestroyDate1 =DATE(YEAR(ProjClosureDate1)+RetentionPeriod1,MONTH(ProjClosureDate1),DAY(ProjClosureDate 1))
function GetField(cName) {
// get field object with error checking;
var oField = this.getField(cName);
if(cName == null) app.alert("Error accessing field " + cName + "\nPlease check the existence of the field and its name.", 1, 0);
return oField;
} // end GetField function;
function Scand(cFormat, cDateString) {
// convert date string to a date object with error checking;
var oDate = util.scand(cFormat, cDateString);
if(oDate == null) app.alert("Error converting " + cDateString + " with format of " + cFormat +"\Please check the format of the date field", 0, 1);
return oDate;
} // end Scand function;
// custom JavaScript calculation for the target field;
// format for dates;
var cFormat = "d-mmm-yy";
// field name for formatted input date;
var cDateField = "ProjClosureDate1";
// field name for the number of years to add;
var cAddYears = "RetentionPeriod1";
// get the field objects;
var oDateField = GetField(cDateField);
var oAddYears = GetField(cAddYears);
event.value = ""; // clear the target field;
// convert date string to date object;
var oDate = Scand(cFormat, oDateField.valueAsString);
// get the full year from the date object;
var nFullYear = oDate.getFullYear();
// add number of years to the full year;
nFullYear += oAddYears.value;
// rest the date object for the new year value;
oDate.setFullYear(nFullYear);
// set the target field with the new date;
event.value = util.printd(cFormat, oDate);
The only problem that I am facing now is that the "DestroyDate1" field is showing the current date prior to having any input in the form that I am making.
please help and modify the script.
thanks