Expand my Community achievements bar.

Concatenate Field Values?

Avatar

Former Community Member
I have created a form that enables a user to rate a set of 20 criteria from 1-7 on the first page. On the second page of the form, I have two calculated - read only text fields. The first is 'Above Average' and the second is 'Needs Improvement.'



Is there a way to have the form look through the criteria ratings on the first page, and for each criteria rated a 5 or higher have the criteria be compiled in the 'Above Average' field, and for those rated a 2 or lower have them compile in the 'Needs Improvement' field?



An example: Let's say of the 20 criteria rated on page one, the person got a rating of 5 for "Flexibility," 6 for "Promptness," and 7 for "Attendance," and they got a rating of 2 for "Tidiness," and 1 for "Safety." (The other 15 criteria were all rated either 3 or 4.)



On page two, in the 'Above Average' field, I would like to see the text: "Flexibility, Promptness, Attendance." And in the 'Needs Improvement' field, I would see "Tidiness, Safety."



I was trying to build something using switch/case on the ratings, but I suspect there's a much better way to do this....
5 Replies

Avatar

Level 7
What is wrong with processing the criteria as each field is completed?



The first field would clear the fields on the second page and then figure if the current field should update any field on the second page. You would need to use the "concat()" funcition to combine the value of the second page field with the current field being tested.

Avatar

Former Community Member
I get the concat function, and I get the switch/case and if functions, but I'm stumped as to how I get them to work together.



So I think you're saying I could add a script to the change event of each criteria that determines the value of the field. If the field value is > 5, it adds the criteria to the 'Above Average' field on the second page. But I'm not sure how to keep each script from wiping the field each time. Would I somehow concat the 'Above Average' field value with the new value?



Thank you for your help, and sorry if I sould completely lost!

Avatar

Level 7
LivCycle Designer has the built-in FormCalc function of "concat(s1 [,s2 ...])" to concatenate strings and JavaScript uses the "+" operator to concatenate strings.



The 'switch()' statement is only available in JavaScript in LiveCycle Designer.



One could use the following script in the "AboveAverage" field



// array of field names used in the evaluation

var aFields = new Array(["Attendance", "Promptness", "Flexibility", ...]);



// loop through the fields

for (i = 0; i < aFields.length; i++){

switch (true) {

case (aFields[i].rawValue > 4) :

// above average actions

AboveAverage.rawValue = AbobeAverage.rawValue + " " + aFields[i];

break;



case ($.rawValue < 3) :

// below average actions

BelowAverage.rawValue = BelowAverage.rawValue + " " + aFields[i];

break;



default:

// no action

break;

} // end swtich

) // end for loop

Avatar

Former Community Member
Geo,



Though I have not gotten it to work yet, I can't thank you enough -- just reading this script and working with it in my form has probably quintupled my understanding of how arrays and loops work (not that I had much to start). However, a requested change has thrown me off just when I might've been about to wrap my head around this. Here's the new request:



My criteria now needs to be in sections. So page one, section one (which I have wrapped in a subform) is Attendance. In the Attendance subform I have the same dropdowns for the 0-7 values, but the captions on the dropdowns are now the criteria I would want to concatenate to the fields on page two. So imagine this:



Page One [new page]

Attendance [subform]

1. Tardiness [Dropdown1]: caption is "Controlled tardiness throughout the year"

2. Overtime [Dropdown2]: caption is "Available for voluntary overtime often"

3. Absenteeism [Dropdown3]: caption is "Controlled absenteeism throughout the year"



Page Two [new page]

AttendanceResults [subform]

A. AboveAverage [text field: calculated from page one]

B. NeedsImprovement [text field: calculated from page one]

C. Comments [User enabled]



So let's say the employee was given a rating of 5.0 on #1, 1.0 on #2, and a 6.0 on #3. The AboveAverage field would populate with "Controlled tardiness throughout the year, Controlled absenteeism throughout the year," and the NeedsImprovement field would populate with "Available for voluntary overtime often"



Did they just completely throw off my form, or is there hope for it yet?



Again, thanks a billion -- I'm quickly catching on to Live Cycle and scripting but haven't had to do anything with loops and concats so far, and the guides can be a bit baffling....

Avatar

Level 7
If you have subforms will have to provide the full hierarchy object, object name and property for the subform field you need to access.