Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Help creating an array

Avatar

Level 2

I'm new to Life Cycle Designer and need help with the following script:

txtComments.rawValue = Page1.Com1.rawValue + "\n" + Page1.Com2.rawValue + "\n" + Page1.Com3.rawValue;

What I'd really like to do is create an array/function that concatenates the fields titled Com* if there is data in these fields on page 1 of my form and display the data in the txtComments field on page 3 of my form. If there is no data, I do not want "null" to display for that field. The final form may have 60+ Com fields... It would be awful to have to hand code each of these. All this is triggered by a specific radio button selection.

I hope someone can help me. Let me know if you have questions. Thanks!

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

What if you put a for loop in and processed it that way ...something like this:

for (i=0;i<=number of com fields;i++){

     if (xfa.resolveNode("Page1.Com" + i).rawValue != null){

          txtComments.rawValue += xfa.resolveNode("Page1.Com" + i).rawValue + ", ";

     }

}

This woudl loop through all of the com fields, check to see if they have a value and if so then add them to the txtComments field.

Paul

View solution in original post

11 Replies

Avatar

Correct answer by
Former Community Member

What if you put a for loop in and processed it that way ...something like this:

for (i=0;i<=number of com fields;i++){

     if (xfa.resolveNode("Page1.Com" + i).rawValue != null){

          txtComments.rawValue += xfa.resolveNode("Page1.Com" + i).rawValue + ", ";

     }

}

This woudl loop through all of the com fields, check to see if they have a value and if so then add them to the txtComments field.

Paul

Avatar

Level 2

Thank you SO much, Paul...

Well, I feel like I'm much closer... I knew how to do a basic loop, but was having a devil of a time trying to figure out the commands for this JS. The only problem is that I'm not getting any data now. I tried using

Alerts(txtComments);

within the loop and outside of the loop in an effort to check the value of the txtComments field... but still see nothing. Idk what to do now.

Caroline

Avatar

Former Community Member

Are you getting any errors in the javascript console?

At thi spoint seeing teh form would be helpful ...can you send it to LiveCycle8@gmail.com

Paul

Avatar

Level 2

I'm at home now, but will send the form from work tomorrow. Thanks so very much!

Avatar

Level 2

Paul,

I've sent 2 versionsn of my form to you. Any help you can provide is greatly appreciated!

Caroline

Avatar

Former Community Member

I did not receive anything like this can you send it again and Identify this thread in the email? The email address is LiveCycle8@gmail.com

Paul

Avatar

Level 2

It works, Paul!!!! Thank you, thank you, thank you!!! I augmented the code slightly to include a break in between the fields. This is what I ended up with:

this.rawValue = " "

for (i=1;i<=72;i++) {

     if (xfa.resolveNode("Page1.Com" + i).rawValue != null ){

          this.rawValue += xfa.resolveNode("Page1.Com" + i).rawValue + "\n";

     }

}

 

Now... the dilemna I have worked around for the time being is this... what if my Com fields flow over into pages 2 and 3? I suppose I could make additional txtComments fields, but that would look odd if nothing is populated on the 1st one and only a couple are say on the 2nd or 3rd page. Does that make sense? I lengthened my paper size in Word to get everything on one page as a work around, but I probably need to remedy this at some point considering I have a number of these forms to create. I played with the code a little bit to try and solve this on my own, but to no avail... yet. Thanks again!

Avatar

Former Community Member

If you have Com fields across pages then you wil see that the expression access those objects will change ...hence you coudl use a for loop for each page. This assumes that you know how many com objcts are on each page. The you woudl adjust your for loop to start and end at the correct values.

If you do not know how many com objects there will be per page (i.e. this is a dynamic form) then there is a completely different approach we can take. Let me which way your form is set up.

Paul

Avatar

Level 2

I got it, Paul! I'm doing a jiggy dance over here! Thanks so very much!!!

Caroline

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----