Copy link to clipboard
Copied
Hello.
I am still learning more about how to create my own custom calculation scripts in Adobe Acrobat Pro 2017 - so I apologize if this seems like a simple question.
The form that I am currently building has a lot of different sections, and multiple date fields in each section. On the "Table of Contents" I want to be able to show for each section, the date last worked. I imagine this would be done by creating a custom calculation script to display the most recent date out of the date fields that I want to be used in the data set...
Is this the best way to approach my issue? If so, how would I tell the custom calculation script to display the most recent date?
Sorry about the delay in replying, this kind of fell between the cracks...
You can use this code as the custom calculation script of the field that should show the latest date:
var dates = [];
for (var i=1; i<=5; i++) {
var v = this.getField("Date"+i).valueAsString;
if (v!="") dates.push(util.scand("mm/dd/yyyy", v));
}
if (dates.length==0) event.value = "";
else {
dates.sort(sortDates);
event.value = util.printd("mm/dd/yyyy", dates[0]);
}
function sortDates(a,b) {
return b.getTime()-a.ge
...
Copy link to clipboard
Copied
Your question is not very clear... Do you mean you have a bunch of date fields filled in by the user, and you want to automatically display the latest value in another field?
Copy link to clipboard
Copied
Thank you for asking a clarifying question! I meant to be more clear in my post above, but I think you understand what I am asking. I may be over complicating this, and if I am I am sorry, but I immensely apprecaite your help.
In "Section1" there are 5 date fields, " Date1, Date2, Date3, Date4, Date5". Each date field has a correspond question and text field (Text1, Text2, Text3, Text4, Text5). As the user enters the data into a text field (Text2) they will manually update the corresponding date field (Date2). On the Table of Contents "Section1" shows a date field titled "S1 Date Last Updated", which should show the most recent date out of the date fields in that section (Date1, Date2, Date3, Date4, Date5).
Copy link to clipboard
Copied
Also - one other issue that I also need to solve for is that on the table of contents I also have a drop down field for each Section that has the following options: "Not Started", "Partial", or "Complete" - want that drop down to automatically update depending on whether any data has been entered into the text fields in the Section. (Not Started = all cells blank, Partial= at least one text box with data in it, Complete= all required text boxes in the section have data). Is that possible?
Copy link to clipboard
Copied
Yes, that's possible, too. Should it depend on the date fields as well as the text fields? Or just the text fields?
Copy link to clipboard
Copied
That's great news! I would like it to depend on only the text fields.
Copy link to clipboard
Copied
What's the date pattern used for the Date fields? mm/dd/yyyy?
Copy link to clipboard
Copied
The date format used for the "S1 Date Last Updated" is currently mm/dd/yyyy. The 5 date fields, " Date1, Date2, Date3, Date4, Date5", are also formatted in a mm/dd/yyyy format. Adobe has been giving me an alert when I try to set the calculation saying the format should match mm/dd/yyyy, but it already is set to match that.
Copy link to clipboard
Copied
Sorry about the delay in replying, this kind of fell between the cracks...
You can use this code as the custom calculation script of the field that should show the latest date:
var dates = [];
for (var i=1; i<=5; i++) {
var v = this.getField("Date"+i).valueAsString;
if (v!="") dates.push(util.scand("mm/dd/yyyy", v));
}
if (dates.length==0) event.value = "";
else {
dates.sort(sortDates);
event.value = util.printd("mm/dd/yyyy", dates[0]);
}
function sortDates(a,b) {
return b.getTime()-a.getTime();
}
Copy link to clipboard
Copied
Hello again. I've been trying to trouble shoot this on my own but am having difficulty...
I have ensured that I am using date fields, and that they all have the format of mm/dd/yyyy. I know that I should use the maximum function to find the most recent date out of a data set, but when I try to select the date fields that I want to determine the max date I recieve an error message that states: "Invalid date/time: please ensure that the date/time exists. Field [ Most Recent_af_date ] should match format mm/dd/yyyy"
If you have any advice on how I might resolve this issue I would appreciate it immensely!