web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Retrieve single record...
Power Pages
Answered

Retrieve single record using FetchXML by passing Id parameter and display in Web Page as per the layout

(0) ShareShare
ReportReport
Posted on by 7,044 Most Valuable Professional

Hello Folks, 

 

Requirement: When the user types in the "id number" on a web page and hit the search button. Then I need to retrieve the associated single record from the entities with few attributes and display it on the different web page at various places. 

Below is the design of the requirement 

ragavanrajan_1-1623811019624.png

Here is my attempt on Fetch XML: 

 

 

 

 {% fetchxml get_siteID_details %}
 <fetch version="1.0" output-format="xml-platform" mapping="logical" top="1">
 <entity name="cra0d_sm_site">
 <attribute name="cra0d_sitename" />
 <attribute name="cra0d_sm_sitemasterid" />
 <attribute name="cra0d_contract" />
 <attribute name="cra0d_financialyear" />
 <attribute name="cra0d_raw_financialyear" />
 <attribute name="cra0d_raw_contractname" />
 <attribute name="cra0d_sitemasterid" />
 <filter>
 <condition attribute="cra0d_sm_sitemasterid" operator="eq" value="{{request.params['SiteMasterID']}}" />
 </filter>
 <order attribute="cra0d_sitemasterid" descending="false" />
 <attribute name="cra0d_comments" />
 </entity>
 </fetch>
 {% endfetchxml %}
 {% if siteid_query_result.results.entities.size > 0 %}
 Contact with AB and AC found!
 {% assign siteid_query_result = get_siteID_details.results.entities %}
 AB Name: {{ siteid_query_result.cra0d_contract }}
 
 {% else %}
 No contacts found
 {% endif %}

 

 

 

What is the right approach for the fetch XML? Please advise how to achieve this. 

 

 

Categories:
I have the same question (0)
  • Verified answer
    oliver.rodrigues Profile Picture
    9,471 Most Valuable Professional on at

    Hi @ragavanrajan 

     

    can you try instead of top="1", using count="1"

     

    a few other things to consider, is ID Number the record GUID? If yes you don't need to run a fetch, you can directly do a "retrieve single" using the Entities object: https://docs.microsoft.com/en-us/powerapps/maker/portals/liquid/liquid-objects#entities

     

    If neither works for you.. you can add this condition inside your for loop, and run only the code for the first index:

    {% if forloop.first %}

     

  • OOlashyn Profile Picture
    3,498 Most Valuable Professional on at

    Hi @ragavanrajan ,

    When you retrieve data via fetchxml results will be returned as an array. So get_siteID_details.results.entities is an array. So to get the first record you need get the first element of the array like this: 

    {% assign siteid_query_result = get_siteID_details.results.entities[0] %}
  • ragavanrajan Profile Picture
    7,044 Most Valuable Professional on at

    Both replies are useful. Thank you @OliverRodrigues  and @OliverRodrigues .  Just to clarify once I retrieve the single record. What is the best way to allow users to attach a picture as per the layout. 

     

    Eventually, Few fields should be read-only and the image field should allow users to add their image if they wish to. 

  • oliver.rodrigues Profile Picture
    9,471 Most Valuable Professional on at

    probably web api is the way to go as it seems you need a custom page

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
rezarizvii Profile Picture

rezarizvii 61

#2
11manish Profile Picture

11manish 38

#3
oliver.rodrigues Profile Picture

oliver.rodrigues 30 Most Valuable Professional

Last 30 days Overall leaderboard