Power Pages Fundamentals #19: How to Use Liquid and FetchXML in Power Pages: Quick Read Series

In Power Pages one common scenario was to query dataverse and get details of a record based on some filter condition. This can be achieved in power pages with the combination of liquid and fetchxml .I will explain this by taking a small scenario to display account records which has name as test.

Step 1 : Go to Power Pages Design Studio and then create a new page as shown in below

Step 2 : After Step1, in the selected page select the option edit code which will redirect to visual code online and then inside div element use liquid fetchxml tags as shown below

{% fetchxml accounts %}
{% endfetchxml %}

Step 3 : After Step 2, go to dataverse and use advance find and select account and form the filter criteria with name like ‘test’ and download fetchxml and fetchxml code looks like below

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
          <entity name="account">
            <attribute name="name" />
            <attribute name="primarycontactid" />
            <attribute name="telephone1" />
            <attribute name="accountid" />
            <order attribute="name" descending="false" />
            <filter type="and">
              <condition attribute="name" operator="like" value="%test%" />
            </filter>
          </entity>
        </fetch>

Step 4: After Step3, Go back to webpagecopy.html and paste the above fetchxml code inside fetchxml liquid tags as shown below

  {% fetchxml accounts %}
        <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
          <entity name="account">
            <attribute name="name" />
            <attribute name="primarycontactid" />
            <attribute name="telephone1" />
            <attribute name="accountid" />
            <order attribute="name" descending="false" />
            <filter type="and">
              <condition attribute="name" operator="like" value="%test%" />
            </filter>
          </entity>
        </fetch>
        {% endfetchxml %}

Step 5 : After Step 4, we can print the results that are present on accounts variable that is present in fetchxml liquid tag with a for loop and final code look like this

<div class="row sectionBlockLayout text-start" style="min-height: auto; padding: 8px;">
    <div class="container" style="display: flex; flex-wrap: wrap;">
      <div class="col-lg-12 columnBlockLayout" style="padding: 16px; margin: 60px 0px; min-height: 200px;"></div><p>
        {% fetchxml accounts %}
        <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
          <entity name="account">
            <attribute name="name" />
            <attribute name="primarycontactid" />
            <attribute name="telephone1" />
            <attribute name="accountid" />
            <order attribute="name" descending="false" />
            <filter type="and">
              <condition attribute="name" operator="like" value="%test%" />
            </filter>
          </entity>
        </fetch>
        {% endfetchxml %}
        {% for acc in accounts.results.entities %}
 <p>{{ acc['name'] }}</p>
      </br>
 {% endfor %}
      </p>
    </div>
  </div>

As shown in the below screen shot

Step 6: After Step 5, sync and preview page and the result will be shown as below

Note:

  1. One should login(Authenticated Users /Administrators) to the site to see this record result.
  2. For Anonymous users blank screen will be shown.
  3. Properly frame fetchxml with advanced find or xrmtool box fetchxml builder [https://fetchxmlbuilder.com/] Thanks to Jonas Rapp for making this awesome tool.

Discover more from Common Man Tips for Power Platform, Dynamics CRM,Azure

Subscribe to get the latest posts sent to your email.

Leave a comment