We sometimes get the request to support repetitions in a text item and although we do think this is a feature we would like to implement, we have not gotten round to it yet as there is in most cases a (not very user friendly) workaround. To explain this we use the example of a set of persons:
Instance ID | Person.name | Person.age |
---|---|---|
Person1 | "Kim" | 25 |
Person2 | "Rick" | 30 |
Person3 | "Bob" | 35 |
Person4 | "Bob | 36 |
Simple cases
For this workaround we use the possibility to add fields to a text item in which we can model collects
to give us a set of values which we can join into a presentable string. This would look similar to:
JOIN( ( COLLECT Person.name FROM ALL Person ) , ", " )
This would result in a comma separated string of persons. However, as explained in the collection functions documentation this will only show the unique elements in the set. So if you have the collection of persons as shown above. The resulting string would be:
"Kim, Rick, Bob"
One solution could be to add more unique elements in the collection resulting in something like:
JOIN( ( COLLECT Person.name + " " + Person.age FROM ALL Person ) , ", " )
Which could give us the string with all persons and ages if the combinations of the two are unique. In our case this would be:
"Kim 25, Rick 30, Bob 35, Bob 36"
Unique strings and replacement
In cases where it is unwanted to add or where this still not results in a unique string (i.e. both Bobs having the same age) we can use some more complex expression to still give us the correct results for this solution we make use of the text function replace, add a unique element to each instance and replace it with an empty string. It will look like this:
REPLACE( "/*.+?*/" , JOIN( COLLECT Person.name + "/*" + Person + "*/" FROM ALL Person ,","),"")
In this example we collect the names of all persons and add the instance ID to the string between two identifiable characters. In the example we used the standard comment characters used in Blueriq, but this could be any identifiable character sets. In the replace function we use a simple regular expression to search for these characters and replace these and everything in between with a an empty string ("" at the end).
In our case, this will result in the string:
"Kim, Rick, Bob, Bob"
Static text repeat
In a variation on this, we could also repeat static text. where this:
COLLECT "TEST" FROM ALL Person
Would in our case result in the string:
"TEST"
As there is only one unique element in the collection.
If we want to show this string for all Persons we would have to do this:
REPLACE( "/*.+?*/" , JOIN( COLLECT "TEST" + "/*" + Person + "*/" FROM ALL Person ,", "),"")
Which would result in:
"TEST, TEST, TEST, TEST"
2 Comments
Unknown User (m.schadd)
Unknown User (r.arts)
Duidelijk artikel.