Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Pages - Power Apps Portals
Suggested answer

Processing FetchXML in Liquid

(0) ShareShare
ReportReport
Posted on by 2
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!
Categories:
  • Suggested answer
    oliver.rodrigues Profile Picture
    9,327 Most Valuable Professional on at
    Processing FetchXML in Liquid
    A way to do this is by creating Liquid variables and assign the last parent record and compare the values in your loop.
     
    I have an example that I used recently in a presentation, see if the code below helps you:
     
    <div class="row sectionBlockLayout text-left" style="min-height: auto; padding: 8px;"></div>
        <div class="container" style="display: flex; flex-wrap: wrap;">
            {% fetchxml menuItems %}
            <fetch mapping='logical'>
                <entity name='ipps_menu'>
                    <attribute name='ipps_menuid'></attribute>
                    <attribute name='ipps_menu1'></attribute>
                    <attribute name='ipps_category'></attribute>
                    <attribute name='ipps_description'></attribute>
                    <attribute name='ipps_price'></attribute>
                    <order attribute='ipps_category' descending='false'></order>
                </entity>
            </fetch>
            {% endfetchxml %}
            {% assign currentCategory = "" %}
            {% for item in menuItems.results.entities %}
                {% if item.ipps_category.label != currentCategory %}
                    {% if currentCategory != "" %}</div>{% endif %}
                    <div class="col-md-12"><h2>{{ item.ipps_category.label }}</h2></div>
                    <div class="row">
                    {% assign currentCategory = item.ipps_category.label %}
                {% endif %}
                <div class="col-md-4">
                    <div class="card" style="margin: 10px;">
                        <div class="card-body">
                            <h4 class="card-title">{{ item.ipps_menu1 }}</h4>
                            <p class="card-text">{{ item.ipps_description }}</p>
                            <p class="card-text"><strong>Price: </strong>{{ item.ipps_price }}</p>
                        </div>
                    </div>
                </div>
            {% endfor %}
            </div>
        </div>
    </div>

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Pages

#1
Lucas001 Profile Picture

Lucas001 60 Super User 2025 Season 1

#2
Fubar Profile Picture

Fubar 55 Super User 2025 Season 1

#3
surya narayanan Profile Picture

surya narayanan 35