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

Auto Populate Due Date using Check Boxes

Explorer ,
Feb 15, 2023 Feb 15, 2023

Copy link to clipboard

Copied

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

Views

788

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Feb 15, 2023 Feb 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.

 

Votes

Translate

Translate
Community Expert ,
Feb 15, 2023 Feb 15, 2023

Copy link to clipboard

Copied

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.

 

Votes

Translate

Translate

Report

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