Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Auto Populate Due Date using Check Boxes

Explorer ,
Feb 15, 2023 Feb 15, 2023

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 = "";
}

 

TOPICS
Create PDFs , How to , JavaScript , PDF forms
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Feb 15, 2023 Feb 15, 2023
LATEST

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.

 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 15, 2023 Feb 15, 2023
LATEST

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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines