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

Calculated date offset no showing in alternate field

New Here ,
Jun 17, 2025 Jun 17, 2025

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.

TOPICS
JavaScript , PDF forms
181
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 ,
Jun 17, 2025 Jun 17, 2025
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 ,
Jun 17, 2025 Jun 17, 2025
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
New Here ,
Jun 17, 2025 Jun 17, 2025
LATEST

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

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 ,
Jun 17, 2025 Jun 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Jun 17, 2025 Jun 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.

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