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

How to Auto Populate a Date Two Weeks From A Set Start Date

New Here ,
Feb 23, 2024 Feb 23, 2024

Copy link to clipboard

Copied

Hello,

 

I am currently trying to create a pdf that requires a few date boxes.  I have a date box that automatically populates with the date when someone opens the form, but I need to make another box that calculates the date 2 weeks from the first date entered and then auto populate it onto the form.  I have tried several versions of code and cannot seem to get any of them to work for me.  Below is what I have been using and it doesn't come back with any errors but nothing actually auto populates on the pdf form when it opens so the script doesn't seem to be working.  Please advise!

 

var startDate = this.getField("Today").value;

// Convert start date string to a Date object
var startDateObj = util.scand("mm/dd/yyyy", startDate);

// Calculate future date by adding 14 days
var futureDateObj = new Date(startDateObj.getTime());
futureDateObj.setDate(futureDateObj.getDate() + 14);

// Format future date as "YYYY-MM-DD" string
var futureDateString = util.printd("mm/dd/yyyy", futureDateObj);

TOPICS
How to , JavaScript , PDF , PDF forms

Views

150

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 23, 2024 Feb 23, 2024

You didn't set the result to show in a field.

Use this as custom calculation script in a field where you want to show new date:

var startDate = this.getField("Today").value;
var startDateObj = util.scand("mm/dd/yyyy", startDate);

if(startDate == "")
event.value = "";
else{
var futureDateObj = new Date(startDateObj.getTime());
futureDateObj.setDate(futureDateObj.getDate() + 14);
var futureDateString = util.printd("mm/dd/yyyy", futureDateObj);
event.value = futureDateString;}

Votes

Translate

Translate
Community Expert ,
Feb 23, 2024 Feb 23, 2024

Copy link to clipboard

Copied

You didn't set the result to show in a field.

Use this as custom calculation script in a field where you want to show new date:

var startDate = this.getField("Today").value;
var startDateObj = util.scand("mm/dd/yyyy", startDate);

if(startDate == "")
event.value = "";
else{
var futureDateObj = new Date(startDateObj.getTime());
futureDateObj.setDate(futureDateObj.getDate() + 14);
var futureDateString = util.printd("mm/dd/yyyy", futureDateObj);
event.value = futureDateString;}

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
New Here ,
Feb 23, 2024 Feb 23, 2024

Copy link to clipboard

Copied

LATEST

Thank you so much, that worked beautifully!

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