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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Content Snippet with f...
Power Pages
Unanswered

Content Snippet with fetchxml not working

(0) ShareShare
ReportReport
Posted on by

Hello all,

 

I am using a content snippet with a fetchxml to build a table. So far easy.

 

The problem comes when on the portal page I don't see anything, only the table header and no other data.

 

Using {{myquery.xml | escape}} I can get the fetchxml that is running on my portal page. The query I get is the following:

 

<fetch mapping="logical" version="1.0" distinct="true" output-format="xml-platform"> <entity name="cr3cf_portaldeproveedoreslneasdecompra"> <attribute name="cr3cf_portaldeproveedoreslneasdecompraid" /> <filter type="and"> <filter type="or" hint="union"> <condition attribute="cr3cf_contact" operator="eq" value="6d273a2f-84bb-ea11-a812-000d3ab1160e" /> </filter> </filter> </entity> </fetch>

 

But this is incorrect, here's the fetchxml from my code snippet:

{% fetchxml purchlines %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="cr3cf_portaldeproveedoreslneasdecompra">
<attribute name="cr3cf_portaldeproveedoreslneasdecompraid">
<attribute name="cr3cf_remainqty">
<attribute name="cr3cf_purchunit">
<attribute name="cr3cf_purchid">
<attribute name="cr3cf_price">
<attribute name="cr3cf_linenum">
<attribute name="cr3cf_lineamount">
<attribute name="cr3cf_itemname">
<attribute name="cr3cf_itemid">
<attribute name="cr3cf_discpercent">
<attribute name="cr3cf_discamount">
<attribute name="cr3cf_deliverydate">
<attribute name="cr3cf_contact">
<attribute name="cr3cf_categoryname">
<attribute name="cr3cf_purchaseheader">
<order attribute="cr3cf_linenum" descending="false">
<filter type="and">
<condition attribute="cr3cf_purchaseheader" operator="eq" uitype="cr3cf_portalproveedorescabeceradecompras" value="{{request.params.id}}">
</condition></filter>
</order></attribute></attribute></attribute></attribute></attribute></attribute></attribute></attribute></attribute></attribute></attribute></attribute></attribute></attribute></attribute></entity>
</fetch>
{% endfetchxml %}
 
It is totally different from the one that appears when executing {{myquery.xml | escape}}, has this happened to someone else? Can you help me?

 

I attach a document where I better explain the problem.

 

Thanks!

 

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

    Hi

     

    can you try closing the tags on the attributes: 

    <attribute name="cr3cf_contact"/>
     
    also have you check the size of the list to make sure it's bringing results? 
    have you made sure you have Entity Permissions for the entity you are querying? {{ purchlines.results.entities.size }} 
     

    ------------

    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.

     
  • Community Power Platform Member Profile Picture
    on at

    Hi Oliver,

     

    Thank's for your quick response.

     

    I've assigned all the entity permissions for the enntity I'm querying.

     

    About "also have you check the size of the list to make sure it's bringing results? " I don't, because my query in my content snippet is not loaded in the page.

     

    The page has this: <fetch mapping="logical" version="1.0" distinct="true" output-format="xml-platform"> <entity name="cr3cf_portaldeproveedoreslneasdecompra"> <attribute name="cr3cf_portaldeproveedoreslneasdecompraid" /> <filter type="and"> <filter type="or" hint="union"> <condition attribute="cr3cf_contact" operator="eq" value="6d273a2f-84bb-ea11-a812-000d3ab1160e" /> </filter> </filter> </entity> </fetch>

     

    NOT the query I'm defining in my content snippet. This is the real problem... I don't understand this.

     

    Thanks!

     

     

  • justinburch Profile Picture
    Microsoft Employee on at

    Hi @Anonymous,

    The issue is most likely the lack of closing the attributes, as Oliver pointed out. Your fetch is ignoring all of those open tags and adjusting your fetch query to meet the Entity Permissions (I've written a few articles on what's going on here, if you're interested - https://justinburch.com/portal-security-1/ talks about how the Portal manipulates your query to inject permissions, and https://justinburch.com/portal-security-2/ talks about ways to see this, using the myfetchxml.xml object you used). So take your query, remove all attribute and condition tags (since you didn't end them), and add in additional conditions to link the records back to your contact, and this all explains the query you're seeing.

    It might be helpful to use XrmlToolBox's FetchXml Tester plugin to test and format your Fetch queries before putting them in the code.

  • CliveOld Profile Picture
    6 on at

    I had this issue with content snippets today, when you save the snippet it changes the fetch to be invalid.

    All the elements that have an inline closing brace break

    e.g. <attribute name="cr3cf_remainqty" />

    and <order attribute="cr3cf_linenum" descending="false" />

     

    Resolution make all inline closing blocks nested:

    e.g. <attribute name="cr3cf_remainqty" ></attribute>

    and <order attribute="cr3cf_linenum" descending="false" ></order>

     

    Your xml should be:

     

    {% fetchxml purchlines %}
    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
    <entity name="cr3cf_portaldeproveedoreslneasdecompra">
    <attribute name="cr3cf_portaldeproveedoreslneasdecompraid"></attribute>
    <attribute name="cr3cf_remainqty"></attribute>
    <attribute name="cr3cf_purchunit"></attribute>
    <attribute name="cr3cf_purchid"></attribute>
    <attribute name="cr3cf_price"></attribute>
    <attribute name="cr3cf_linenum"></attribute>
    <attribute name="cr3cf_lineamount"></attribute>
    <attribute name="cr3cf_itemname"></attribute>
    <attribute name="cr3cf_itemid"></attribute>
    <attribute name="cr3cf_discpercent"></attribute>
    <attribute name="cr3cf_discamount"></attribute>
    <attribute name="cr3cf_deliverydate"></attribute>
    <attribute name="cr3cf_contact"></attribute>
    <attribute name="cr3cf_categoryname"></attribute>
    <attribute name="cr3cf_purchaseheader"></attribute>
    <order attribute="cr3cf_linenum" descending="false"></order>
    <filter type="and">
    <condition attribute="cr3cf_purchaseheader" operator="eq" uitype="cr3cf_portalproveedorescabeceradecompras" value="{{request.params.id}}">
    </condition></filter>
    </entity>
    </fetch>
    {% endfetchxml %}
  • ryanspain Profile Picture
    100 on at

    The trick here to stop the Fetch XML from being incorrectly formatted in the content snippet, is set the content snippets Type to Text, not HTML.

    If you use HTML as the Type, the monaco editor seems to try and help format the Fetch XML query such that it cannot be executed correctly.

    Use Text as the Type when using Fetch XML in content snippets. Alternatively, use web templates to hold your Fetch XML queries; I've never had to fix a broken query in a web template.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Jerry-IN Profile Picture

Jerry-IN 71

#2
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard