Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Check the calculation order:
https://pdfautomationstation.substack.com/p/pdf-field-calculation-order-matters
Copy link to clipboard
Copied
Check the calculation order:
https://pdfautomationstation.substack.com/p/pdf-field-calculation-order-matters
Copy link to clipboard
Copied
Setting the calculation order appripriately was the fix, thank you.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now