Skip to main content
Participant
June 17, 2025
Answered

Calculated date offset no showing in alternate field

  • June 17, 2025
  • 3 replies
  • 413 views

I am using the following code to determine if the field "WeekEndingDat" is blank, to automatically set it to the upcoming Sunday.

 

//declare variables; get the date string from date field object
var f = this.getField("WeekEndingDate").value;
var d = util.scand("mm/dd/yyyy", f);
var t = new Date();
var x = t.getDay();

//check if WeekEndingDate field is blank
if (f=="") {

//if blank, set date value to next Sunday
t.setDate(t.getDate()+(7-x));

//display the output of the new date in the desired date format
event.value = util.printd("mm/dd/yyyy", t);

}

else {

event.value=util.printd("mm/dd/yyyy", d);

}

 

This works fine for the field with the calculation when I either manually add a date or delete the data and the new upcoming Sunday date is automatically populated in this field.

 

I have an alternate field which is to also use the same date from the calculated field. Whenever I manually enter a date, the alternate field works properly. However, when I delete the data from the initial field, the alternate field automatically populates with the current date (not upcoming Sunday). The code for the alternate field is 

 

// Get the date string from the date field object
var f = this.getField("WeekEndingDate").value;
var d = util.scand("mm/dd/yyyy", f);

 

// Display the new date in the desired format
event.value = util.printd("mm/dd/yyyy", d);

 

Any help is appreciated.

Correct answer PDF Automation Station

Check the calculation order:

https://pdfautomationstation.substack.com/p/pdf-field-calculation-order-matters

3 replies

PDF Automation Station
Community Expert
Community Expert
June 17, 2025

Is the alternative field always the same value as WeekEndingDate?  Why not set the value to WeekEndingDate value?  Or better yet, name the fields the same.

Thom Parker
Community Expert
Community Expert
June 17, 2025

Run your code line by line manually in the Console Window, and you'll see where it is going wrong.

 

https://www.pdfscripting.com/public/images/video/AcroJSIntro/AcroJSIntro_ConsoleWindow.cfm

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
PDF Automation Station
Community Expert
Community Expert
June 17, 2025
Participant
June 17, 2025

Setting the calculation order appripriately was the fix, thank you.