Skip to main content

Notifications

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
    oliver.rodrigues 8,899 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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #9 Get Recognized…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,867

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,174

Leaderboard