Copy link to clipboard
Copied
I have 4 solutions with different expiry dates and I need to assign the earliest expiry date among the 4 for the final product. I am using Acrobat Pro and any help is greatly appreciated. Thanks!
The dates array is for the values. If you want to hard-code the field names then use this:
var dateFormat = "mm/dd/yyyy";
var fields = ["801080EXP","801016EXP","801017EXP","801018EXP"];
var dates = [];
for (var i in fields) {
var f = this.getField(fields);
var v = f.valueAsString;
if (v!="") dates.push(util.scand(dateFormat, v));
}
if (dates.length==0) event.value = "";
else {
dates.sort(function(a, b){return a.getTime() - b.getTime()});
event.value = util.printd(dateFormat, dates[0]);
}
Copy link to clipboard
Copied
Let's say the fields are named ExpiryDate1 to ExpireDate4, and that their date format is mm/dd/yyyy. You can use this code as the custom calculation script of the field where you want to display the earlier of the four values:
var dateFormat = "mm/dd/yyyy";
var dates = [];
for (var i=1; i<=4; i++) {
var f = this.getField("ExpiryDate"+i);
var v = f.valueAsString;
if (v!="") dates.push(util.scand(dateFormat, v));
}
if (dates.length==0) event.value = "";
else {
dates.sort(function(a, b){return a.getTime() - b.getTime()});
event.value = util.printd(dateFormat, dates[0]);
}
Copy link to clipboard
Copied
Tried to substitute with what you've posted but couldn't get it right. It's not showing any result. I think I'm not doing it correctly. Here's my script:
var dateFormat = "yyyy-mm-dd";
var dates = ["801080EXP","801016EXP","801017EXP","801018EXP"];
for (var i=1; i<=4; i++) {
var f = this.getField(["ExpDate"]+i);
var v = f.valueAsString;
if (v!="") dates.push(util.scand(dateFormat, v));
}
if (dates.length==0) event.value = "";
else {
event.value = util.printd(dateFormat, dates[0]);
}
the enclosed var dates are the field names for each component's expiry date and the finished product expiry date field name is "ExpDate".
Sorry for such a nuisance and thanks a lot for taking the time to reply!
Copy link to clipboard
Copied
The dates array is for the values. If you want to hard-code the field names then use this:
var dateFormat = "mm/dd/yyyy";
var fields = ["801080EXP","801016EXP","801017EXP","801018EXP"];
var dates = [];
for (var i in fields) {
var f = this.getField(fields);
var v = f.valueAsString;
if (v!="") dates.push(util.scand(dateFormat, v));
}
if (dates.length==0) event.value = "";
else {
dates.sort(function(a, b){return a.getTime() - b.getTime()});
event.value = util.printd(dateFormat, dates[0]);
}
Copy link to clipboard
Copied
it worked! a million thanks to you. !