Hello!
I have a field coming from a datasource that holds a list of values in a comma separated structure. I need to convert this into a text field containing 1 row for each value.
Is there an easy way to do this using functions (e.g. split, join) rather than looping through an Iterator module? Thanks.
From:
ImpactedEntities=A,B,C
To:
ImpactedEntities=A
ImpactedEntities=B
ImpactedEntities=C
Figured it out.
Had to use a combination of split and join.
In case this helps anyone else in the future, here is what I did:
{{space}}|Impacts Entities={{join(split(97.fields.EntitiesImpacted; “,”; “false”); newline + space + “|Impacts Entities=”)}}
Explanation:
The call to ‘Split’ converts the CSV list into a simple array; the false parameter prevents empty values from being added to the array.
The join assembles the list back together, but the delimeter comes at the end: for the first row you would get => “A|Impacts Entities=”
Adding the newline to the delimeter results in:
A
|Impacts Entities=
For each additional row, the next value will appear right after the delimiter of the previous row.
A
|Impacts Entities=B |Impacts Entities=
Finally add an initial delimiter at the beginning of the whole thing to handle the first row: |Impacts Entities= A
|Impacts Entities=B
|Impacts Entities
Now, in case you’re wondering what happens on the last row, when there is just a delimiter fragment with no value, the truth is - I have no idea.
For some reason, it’s working with whatever number of values I’ve tossed at it. I’ve had fields with 1,2 and 3 values so far and each time I get the correct number of x=y rows with no weirdness at the end. If someone else can explain I’m all ears. Right now I’m half asleep and my logic facilities are not up to the task to figure this out.