InfoPath: Concatenating fields in repeating tables (merging values into a single field) 

Trying to build InfoPath forms with complicated logic WITHOUT code is pushing InfoPath beyond some of its limits.  Nonetheless, I did some research and was able to come up with an expression that will return a concatenated string of filtered values from a repeating table which basically merges the values in a repeating field into a single field.

Using a hacked together IF-like statement from http://blogs.msdn.com/infopath/archive/2006/11/27/conditional-default-values.aspx and the double eval() trick in http://blogs.msdn.com/infopath/archive/2006/04/05/569338.aspx, I arrived at this:

xdMath:Eval(xdMath:Eval(../my:Group/my:RepeatingGroup, 'substring(concat(my:Value, ";"), 1, (my:Select = string(true())) * string-length(concat(my:Value, ";")))'), "..")

This return a semi-colon-delimited list of Values where Select has been checked and evaluates to TRUE

With this schema:

  • Group
    • RepeatingGroup
      • Select
      • Value

The double eval() trick merely loops through a repeating list. The key to filtering is in the calculation performed in the nested eval() function. That's where the IF-like statement comes in.

It starts with the substring() function.

substring (string, start-position, end-position)

Where

string = concat(my:Value, ";")
start-position = 1
end-position =(my:Select = string(true())) * string-length(concat(my:Value, ";")))

Here's what I want in my concatenated string:

concat(my:Value, ";")

But I only want it if my:Select = TRUE so to evaluate whether my:Select = TRUE:

my:Select=string(true())

If this operation returns TRUE, the result will be a 1

If the operation returns a FALSE, the result will be a zero (0)

Using the length of the text I want to return as a multiplier, I'll either get a zero or I'll get the length of the entire string:

(my:Select=string(true()))* (string-length(concat(my:Value, ";")))

Pulling that together with the substring() function, it will return either a zero-length string or the entire text I want returned:

substring(concat(my:Value, ";"), 1, (my:Select=string(true()))*(string-length(concat(my:Value, ";"))))

Drop this into the calculation parameter in the nested eval() function and you're done.

My example returns one field based on the value of another field in that same repeating node. I use it to return a list of the selected values in a hacked-together, browser-enabled version of a multi-select list box.  If you want to return only non-blank fields, you can move some stuff around and make it simpler.  Well, simpler maybe to some.

eval(eval(RepeatingGroup, 'concat(my:Value, substring(";", 1, string-length(my:Value)))'), "..")

-Ann T. Ho Senior Analyst
Comments
No Comments Available
Add a New Comment
Name

Email Address

Url

Comment