Skip to main content
Participant
Mar 14, 2025 7:09 PM UTC
Answered

script to auto populate one text field with other text fields on separate lines

Can you please help me with a script to auto populate Text9 with Text1, Text2, and Text3 on thier own seperate lines?

try67
try67Correct answer
Community Expert
Mar 14, 2025 10:12 PM UTC

Then you can use something like this as the custom calculation script of "Text9":

 

var fields = ["Text1", "Text2", "Text3"];
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");

5 replies

PDF Automation Station
Community Expert
Community Expert
Mar 14, 2025 8:23 PM UTC

Make sure Text9 is a multi-line text field and enter the following custom calculation script into it:

var text="";
for(var i=1;i<4;i++)
{
if(this.getField("Text"+i).value)
{
text+=this.getField("Text"+i).value+"\n";
}
}

event.value=text;
Translate
try67
Community Expert
Community Expert
Mar 14, 2025 7:19 PM UTC

Should there be an empty line if the fields are empty?

Translate
Participant
Mar 14, 2025 7:42 PM UTC

no need for an empty line. thank you.

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Mar 14, 2025 10:12 PM UTC

Then you can use something like this as the custom calculation script of "Text9":

 

var fields = ["Text1", "Text2", "Text3"];
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");
Translate