Copy link to clipboard
Copied
I would like Text1 to read:
NAME
ADDRESS
CITY, STATE, ZIP
var fields = ["NAME", "ADDRESS", "CITY", "STATE", "ZIP"];
var values = [];
for (var i in fields) {
var f = this.getField(fields[i]);
if (f.valueAsString!="") values.push(f.valueAsString);
}
event.value = values.join("\n");
Copy link to clipboard
Copied
Then the fields values need to be joined differently.
For example:
var fields = ["NAME", "ADDRESS", "CITY", "STATE", "ZIP"];
var aFldVals = fields.map(cNm=>this.getField(cNm).value);
event.value = aFldVals[0] + "\n" + aFldVals[1] + "\n" + aFldVals[2] + ", " + aFldVals[3] + ", " + aFldVals[4];
Copy link to clipboard
Copied
Have you a question?
Copy link to clipboard
Copied
Is your code a calculation script on the "Text1" field? If it is, then this is the correct way to do it.
Did you check the console window for errors? If you had you would probably see a type error being reported. This is because of the incorrect usage of the "for/in" loop. Use a regular for loop and it'll work.
Copy link to clipboard
Copied
Here is another way to write the code:
var fields = ["NAME", "ADDRESS", "CITY", "STATE", "ZIP"];
event.value = fields.map(cNm=>this.getField(cNm).value).join("\n");
Copy link to clipboard
Copied
Text1 is showing:
NAME
ADDRESS
CITY
STATE
ZIP
But I would like the City, State, & Zip to be on the same line instead of stacked.
Copy link to clipboard
Copied
Then the fields values need to be joined differently.
For example:
var fields = ["NAME", "ADDRESS", "CITY", "STATE", "ZIP"];
var aFldVals = fields.map(cNm=>this.getField(cNm).value);
event.value = aFldVals[0] + "\n" + aFldVals[1] + "\n" + aFldVals[2] + ", " + aFldVals[3] + ", " + aFldVals[4];
Copy link to clipboard
Copied
That worked! Thank you!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now