Copy link to clipboard
Copied
Hello,
I am using Adobe Acrobat XI Pro. I have created a Custom Calculation Script to combine the fields "Date" and "CountyDD" into a third field called "CountyDateCombo." The "CountyDD" field is a dropdown allowing the end user to select counties from a list. The Custom Calculation Script in the "CountyDateCombo" field is as follows:
// Get the field values, as strings
var s1 = getField("CountyDD").valueAsString;
var s2 = getField("Date").valueAsString;
// Combine values, separated by a space
event.value = "In " + s1 + " County, on " + s2 + ".";
The date format I need for the "Date" field is mm-dd-yyyy (e.g. 05-20-2018), however, the date format I need for the "CountyDateCombo" field is mmmm d, yyyy (e.g. May 20, 2018). I am combining the two fields so the final combined field would read e.g. "In Hennepin County, on May 20, 2018." I have not been able to figure out how to change the date format in the "CountyDateCombo" field and was hoping someone out there can give me so assistance.
Thank you in advance
Steve
Copy link to clipboard
Copied
A line was out of the correct order.
// Get the field values, as strings;
var s1 = getField("CountyDD").valueAsString;
var s2 = getField("Date").valueAsString;
// reformat the date string;
var oS2 = util.scand("mm-dd-yyyy", s2);
var s3 = util.printd("mmmm d, yyyy", oS2)
// Combine values, separated by a space
event.value = "In " + s1 + " County, on " + s3 + ".";
Copy link to clipboard
Copied
Acrobat JavaScript includes concatenation either by use of the "concat" method or the "+" operator when used with a string. You will also need to convert you "Date" field value to the "mmm d, yyyy" format.
// Get the field values, as strings;
var s1 = getField("CountyDD").valueAsString;
var s2 = getField("Date").valueAsString;
var s3 = util.printd("mmmm d, yyyy", oS2)
// reformat the date string;
var oS2 = util.scand("mm-dd-yyyy", s2);
// Combine values, separated by a space
event.value = "In " + s1 + " County, on " + s3 + ".";
Copy link to clipboard
Copied
Hi gkaiseril,
Thank you for your response. I copied your code into my Custom Calculation script and changed the "Date" field to "mmmm d, yyyy" format as suggested and nothing happened. The only thing that did change was the format for the "Date" field, which changed to "mmmm d, yyyy" format. I am wondering if something is missing because nothing gets updated even if I change the county from the dropdown list.
Also is it possible to keep the "Date" field format as mm-dd-yyyy instead of changing it to mmmm d, yyyy?
Steve
Copy link to clipboard
Copied
A line was out of the correct order.
// Get the field values, as strings;
var s1 = getField("CountyDD").valueAsString;
var s2 = getField("Date").valueAsString;
// reformat the date string;
var oS2 = util.scand("mm-dd-yyyy", s2);
var s3 = util.printd("mmmm d, yyyy", oS2)
// Combine values, separated by a space
event.value = "In " + s1 + " County, on " + s3 + ".";
Copy link to clipboard
Copied
Thank you very much. Works perfectly!!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more