Skip to main content
Participant
March 14, 2025
Answered

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

  • March 14, 2025
  • 2 replies
  • 472 views

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

Correct answer try67

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");

2 replies

PDF Automation Station
Community Expert
Community Expert
March 14, 2025

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;
try67
Community Expert
Community Expert
March 14, 2025

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

Participant
March 14, 2025

no need for an empty line. thank you.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
March 14, 2025

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");