• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
5

Is it possible to populate a field with data from only one (1) of 10 potential fields?

Contributor ,
Oct 25, 2023 Oct 25, 2023

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   

TOPICS
How to , JavaScript , PDF

Views

241

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 25, 2023 Oct 25, 2023

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;}}

Votes

Translate

Translate
Community Expert ,
Oct 25, 2023 Oct 25, 2023

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?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 25, 2023 Oct 25, 2023

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 25, 2023 Oct 25, 2023

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;}}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 25, 2023 Oct 25, 2023

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 25, 2023 Oct 25, 2023

Copy link to clipboard

Copied

LATEST

Change i>=10 to i<=10.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines