I am trying to do some processing on the output of the fetchXML response using liquid, however I'm having an issue with this. The FetchXML is using a 1:M join and so I'm getting duplicate responses. I wanted to iterate over the response and collapse into a nested array inside of an object. To do this, I tried this:
{% assign groupedRecords= {} %}
{% for rec in records.results.entities %}
{% assign recId= rec.recId%}
{% if groupedRecords[recId] == null %}
{% assign groupedRecords= groupedRecords | merge: { recid: {"attr1": rec.attr1, "createdon": rec.createdon, "array": []}} %}
{% endif %}
{% if rec["attachment.attr"] %}
{% assign tempArray = groupedRecords[recId].array%}
{% assign updatedArray= tempArray | push: rec["attachment.attr"] %}
{% assign groupedMessages[recId].array= updatedArray %}
{% endif %}
{% endfor %}
This is not working at all, I get errors at the first line since it seems creating that empty dictionary does not seem supported. Because of this, it seems like the groupedRecords dictionary is not getting set at all either.
I've tried a few other ways using arrays instead of a dictionary, but can't seem to make any progress. I am thinking the best way to do this is to just move the entire logic into JS and pass the records in a script tag.
Any help would be greatly appreciated. Thanks!