Skip to main content
Sonny AR
Inspiring
February 15, 2023
Answered

Auto Populate Due Date using Check Boxes

  • February 15, 2023
  • 1 reply
  • 1109 views

Hello Members,

I want to auto-calculate the due date field with the condition of two check boxes and a start date.
If one box is checked it should fill due date with an addition of 3 months.
If the 2nd box is checked it should fill date with an addition of 1 year.

 

Note: a) The due date should appear one day less.  b) February have 28 days

 

Kindly check the attachment.

 

I'm using this script in "DueDate" text field but I can't figure out how can i add "StartDate" field as a reference of the Start Date in this script.

var date = new Date();

var addTime = this.getField("AddTime").value;

var days = 0;
if (addTime != "Off") {
    switch (addTime) {
    case "91days" : 
        days = 90;
        break;
    case "365days" :
        days = 364;
        break;
   
    }
    date.setDate(date.getDate()+days);
    event.value = util.printd("dd-mmm-yyyy", date);
}
else {
    event.value = "";
}

 

This topic has been closed for replies.
Correct answer try67

Change the code to this:

 

var startDate = this.getField("StartDate").valueAsString;
if (startDate=="") event.value = "";
else {
	var date = util.scand("dd-mmm-yyyy", startDate);
	// rest of the code goes here
}

 

Re your notes:

a. Then just add one day less...

b. That's taken care of automatically when you use the setDate method.

 

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 15, 2023

Change the code to this:

 

var startDate = this.getField("StartDate").valueAsString;
if (startDate=="") event.value = "";
else {
	var date = util.scand("dd-mmm-yyyy", startDate);
	// rest of the code goes here
}

 

Re your notes:

a. Then just add one day less...

b. That's taken care of automatically when you use the setDate method.