+1 vote
in Rock by (13.1k points)
edited

Originally posted by Unknown

If I have a comma-separated list of something, how can I loop through it and process each one?

1 Answer

+1 vote
by (13.1k points)
edited
 
Best answer

Originally posted by Unknown

You can do something like this:

Make sure to change the Highlighted Attribute "GroupMemberGuids" to whatever the attribute key is you are using. It needs to be changed both places you use a "Lava Run" action

enter image description here

Get First Item Lava

{% assign remainingItems = Workflow | Attribute:'YOUR_ATTRIBUTE_KEY','RawValue' | Split:',' %}{{ remainingItems[0] }}

Update Remaining Lava

{% assign remainingItems = Workflow | Attribute:'YOUR_ATTRIBUTE_KEY','RawValue' | Split:',' %}
{% assign firstItem = remainingItems | First %}
{% assign lastItem = remainingItems | Last %}
{% assign result = '' %}
{% for item in remainingItems %}
    {% if item != firstItem %}
        {% capture result %}{{ result }}{{ item }}{% if item != lastItem %},{% endif %}{% endcapture %}
    {% endif %}
{% endfor %}
{{ result }}
by (13.1k points)
(Originally by Unknown) Thanks!
by (13.1k points)
(Originally by Unknown) @MasonKinyon You're welcome
Welcome! Here you can ask questions and receive answers (hopefully) from other members of our team.
...