Skip to content
Franco Mussopower pages
Raindrops hanging from a ceiling
Photograph · Wang Yifang / Unsplash
Guide No.015
SnippetLiquid

Use Liquid and Fetch XML to retrieve a single record without needing a GUID

So you might be wondering why would we use fetch XML to query a single record when we’ve got the super easy to use entities object?

Level
03CustomiseStage 3 of 4
Read
2 min
Includes
1 snippet
Written
Feb 2021

So you might be wondering why would we use fetch XML to query a single record when we’ve got the super easy to use entities object? Well, the difference is that with the entities object, we have to know the GUID, we either have to have queried for it first or we need to have it provided in the URL so that we can use that for the query.

Whereas we’ve using Fetch XML to retrieve a single record. We’ve got much more flexibility. So essentially anything that we do in advanced find we’ll just take it one step further and we’ll apply a particular sort order. So for example, of all the tracks, I want to see them in descending order, by when they were created telling me which is the most recent track.

So sort order is one very important aspect and the other, as you can see highlighted there is I’ve had to specify in the first line of that fetch XML, how many records I want returned. So I want the top one. Okay, but just remember top doesn’t particularly mean anything. It just means that the first result.

So you have to specify with the sort order, what do you mean by top? Do you mean the most recent, the most popular, the highest value, the lowest cost. So remember the sort order is vital.

use Liquid and Fetch XML to retrieve a single record without a GUIDLiquid
{% fetchxml most_recent_track_query %}
    <fetch version="1.0" output-format="xml-platform" mapping="logical" top="1">
        <entity name="musdyn_track">
            <attribute name="musdyn_name" />
            <attribute name="createdon" />
            <order attribute="createdon" descending="true" />
            <filter type="and">
            <condition attribute="statuscode" operator="eq" value="1" />
            </filter>
        </entity>
    </fetch>
{% endfetchxml %}
Go deeper · Power Pages Mastery

This guide is one technique. The course is the method.

The course covers this in Level 3 · Advanced customisation: “Liquid templating for dynamic components”, alongside “Transforming out-of-the-box lists”. A structured programme distilled from dozens of real portal launches — from messy stakeholder requirements to successful go-live.

  • 6 weeks
  • 3 levels
  • Live training + video lessons
Where this fits
  1. Level 1Foundations
  2. Level 2Extending the platform
  3. Level 3Advanced customisation
    • Liquid templating for dynamic components
    • Transforming out-of-the-box lists
Franco’s engaging teaching style made training a pivotal contribution to my professional growth. The walkthrough of a Power Pages site resembling Spotify left an indelible mark.
Bhargav Reddy — Solution Architect — TCS
Filed underLiquid

Comments

No comments yet. Spotted a gotcha I missed? Say so below.

Leave a comment

Your email address won’t be published. Comments are moderated.

Consulting

Need a Power Pages build that editors love and brands survive?

I help teams design and build Power Pages sites with bespoke UX. Tell me about yours.

Search

Book a discovery call

30 minutes. Bring your trickiest Power Pages problem — I’ll tell you honestly whether I’m the right fit.