cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ragavanrajan
Super User
Super User

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

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. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
OliverRodrigues
Super User II
Super User II

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 %}

 




If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

View solution in original post

4 REPLIES 4
OliverRodrigues
Super User II
Super User II

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 %}

 




If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

View solution in original post

OOlashyn
Super User
Super User

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] %}
----------------------------------------------------
If you find this post helpful consider marking it as a solution to help others find it.
ragavanrajan
Super User
Super User

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. 

OliverRodrigues
Super User II
Super User II

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




If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Carousel April Dunnam Updated 768x460.jpg

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Users online (2,163)