Copy link to clipboard
Copied
If I have 10 text fields and wish to populate a separate text field with data from the first field of the 10 containing data, is there a scripting method that would allow me to do so? I have been tinkering and clearly have not been successful so thought I'd ask the Subject Matter Experts (SMEs).
Thanks in advance for any time and assistance!
Very Respectfully,
Charlie
Copy link to clipboard
Copied
Try something like this, it will populate first field that have value, just change field name to your actual field name:
for(var i=1; i<=10; i++){
if(event.value == ""){
if(this.getField("Text"+i).valueAsString !== "")
event.value = this.getField("Text"+i).value;}}
Copy link to clipboard
Copied
Yes, you can use script to do that.
How do you wish to populate the field, automatically as soon as data is entered or via button, checkbox...etc?
What if there are multiple fields that have value, which one should populate field?
Copy link to clipboard
Copied
Good day Nesa! Thank you for responding. 🙂
Ideally, as soon as the field is populated -- my personal preference -- but there may be a requirement for a button depending on what final direction I'm given.
Very Respectfully,
Charlie
Copy link to clipboard
Copied
Try something like this, it will populate first field that have value, just change field name to your actual field name:
for(var i=1; i<=10; i++){
if(event.value == ""){
if(this.getField("Text"+i).valueAsString !== "")
event.value = this.getField("Text"+i).value;}}
Copy link to clipboard
Copied
Thank you Nesa! It works like a champ and is exactly what I needed. 🙂 I took the liberty of modifying it slightly to re-use on a spawned page but my work is never as clean or efficient as yours and the other SMEs. If you have any advice or recommendations, both are appreciated.
var cPreFix = "";
var aFieldName = event.target.name.split(".");
if(aFieldName.length > 2)
{
cPreFix = aFieldName[0] + "." + aFieldName[1] + ".";
}
var result = "";
for (var i = 1; i >= 10; i++) {
var fieldName = cPreFix+"Description." + (i < 10 ? "0" : "") + i;
var field = this.getField(fieldName);
if (field.valueAsString !== "") {
result = field.valueAsString;
break;
}
}
My sincerest thanks for your time and assistance today. 🙂
Very Respectfully,
Charlie
Copy link to clipboard
Copied
Change i>=10 to i<=10.