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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Display result of fetchXML in ADX portal

(0) ShareShare
ReportReport
Posted on by
{% fetchxml my_query %}
  <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
	  <entity name="salesorder">
		<all-attributes/>
		<link-entity name="salesorderdetail" from="salesorderid" to="salesorderid" visible="true" link-type="inner" alias="orderalias">
		  <attribute name="description"/>
		</link-entity>
	  </entity>
	</fetch>
{% endfetchxml %}

{% for result in my_query.results.entities %}
    Order Number: {{ result['orderalias.description'] }}
  {% for res in result['orderalias'] %}
      Order Number: {{ result.ordernumber }} <br/> 
	  Product: {{ res.description }}<hr/>
  {% endfor %}
{% endfor %}


I've been trying to display the result of my link entity together with the parent entity, this is one to many relationship, where salesorder might contain more than one or more salesorderdetails, what i want to do is to display each salesorderdetails for each salesorder. Above is my sample code but unable to display it properly. What am I missing here? What syntax should I use to achieve it? 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Colin V Profile Picture
    on at
    RE: Display result of fetchXML in ADX portal

    This is probably best done in 2 queries for the portal if your trying to create a order details page. You would do a entities.salesorder["<GUID>"] to get the salesorder details. For the details do your fetch but the primary entity to query is salesorderdetail, for those related to the the sales order and that will provide you list of related detail records, the link would be unnecessary.  

    The fetch query the way you have it constructed would return a list of order details with only the description and for each detail record all the attributes of the order.  You have a list of order details, not a list of orders with a list of order details for each order.  Try your query with FetchXML Tester in XrmToolBox to get an idea of what would be returned.

  • Lolitha Profile Picture
    on at
    RE: Display result of fetchXML in ADX portal

    I'm also trying to get fetchXML working with liquid, can someone paste a simple working fetchXML example with liquid please?

  • Colin V Profile Picture
    on at
    RE: Display result of fetchXML in ADX portal

    "Documentation" - it isn't actually documented

    {% fetchxml my_query %}
      <fetch version="1.0" mapping="logical">
        <!-- Write FetchXML here, use Liquid in here if you want, to build XML dynamically. -->
      </fetch>
    {% endfetchxml %}
     
    {{ my_query.xml | escape }}
    {{ my_query.results.total_record_count }}
    {{ my_query.results.more_records }}
    {{ my_query.results.paging_cookie | escape }}
    {% for result in my_query.results.entities %}
      {{ result.id | escape }}
    {% endfor %}
     
    <!-- You can also filter results by Entity Permissions -->
    {% fetchxml secure_query enable_entity_permissions: true, right: 'read' %}
    {% endfetchxml %}


    Example with linked entity:

    {% fetchxml my_query %}
      <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
    	  <entity name="incident">
    		<attribute name="title" />
    		<link-entity name="contact" from="contactid" to="customerid" visible="true" link-type="outer" alias="contactalias">
    		  <attribute name="lastname" />
    		</link-entity>
    	  </entity>
    	</fetch>
    {% endfetchxml %}
    
    {% for result in my_query.results.entities %}
      Case Title: {{ result.title }} <br/> Last Name: {{ result['contactalias.lastname'] }}<hr/>
    {% endfor %}


  • PFD Profile Picture
    on at
    RE: Display result of fetchXML in ADX portal

    Hi all

    I Have an other problem when filtering EntyList with a FetchXMLFilter

    this works fine with this sample :

    <filter type="and">
    <condition attribute="tit_centredelavageid" operator="eq" uiname="MyAccount" uitype="account" value="{6cbc5e0e-0808-e711-8102-3863bb354ff0}" />
    </filter>

    When we try to add dynamic liquid template like this see below, liquid is not parsed and no result appaears...The uiname is displayd "as is" in the page.

    <filter type="and">
    <condition attribute="tit_centredelavageid" operator="eq" uiname="{{user.parentcustomerid.name}}" uitype="account" value="{{user.parentcustomerid.id}}"/>
    </filter>

    Thanks by advance for help!

  • Suggested answer
    Colin V Profile Picture
    on at
    RE: Display result of fetchXML in ADX portal

    Metadata filters as far as I am aware do not support liquid processing.  UI items in fetch are unnecessary for fetchxml to function so you don't need to add them.  You will need to find a way to pass your values to the entity list parameters to re-implement your entity list with a fetchxml yourself manually.

  • Prashanth Kamasamudram Profile Picture
    337 on at
    RE: Display result of fetchXML in ADX portal

    Hi PFD,

    Did you got solution for passing value to fetchxml? I am trying similar thing, want to pass current logged-in users account id to fetchxml condition. How did you archived this?

  • Suggested answer
    duchan Profile Picture
    397 on at
    RE: Display result of fetchXML in ADX portal

    Hi PFD,

    try to use  only value in condition. you don't need to use uiname or uitype. Only guid is fine.

    My condition to customer (account/contact) looks like this:

    <condition attribute="test_customerid" value="{{ user.id }}" operator="eq"/>

    and everything works as it should.

  • Community Member Profile Picture
    on at
    RE: Display result of fetchXML in ADX portal

    I also need to use a query with fetchxml.

    I have this for web template :


      {% entityview logical_name: 'knowledgearticle' , name: 'Derniers articles', page_size: 20 %}
       {% for item in entityview.records %}
         <item>
           <a class="list-group-item" href="{{ item.url | escape }}">
           
                    <div> {{ item.title | escape }} </div>
                    <div class="text-muted small"> {{ item.modifiedon | date: 'd MMM, yyyy' | escape }}</div>
                    <div class="text-muted small"> {{ item.description | escape }}</div></a>
         </item>
       {% endfor %}
      {% endentityview %}


    But i want to add fetchxml to filter what appear. ( in this exemple , all articles about one "city" which is a field on my knowledge article form ).

    How i can do that ?

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Display result of fetchXML in ADX portal

    I was able to make it work using the below sample code.

     {% fetchxml my_query %}
     <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
       <entity name="salesorder" >
         <all-attributes/>
         <link-entity name="salesorderdetail" from="salesorderid" to="salesorderid" link-type="inner" alias="sod" visible="true" >
           <attribute name="productid" />
           <attribute name="productdescription" />
           <attribute name="salesorderid" />
           <attribute name="salesorderdetailid" />
           <attribute name="quantity" />
           <attribute name="productidname" />
           <attribute name="priceperunit" />
           <order attribute="createdon" />
           <link-entity name="product" from="productid" to="productid" link-type="inner" alias="p" visible="true" >
             <attribute name="name" />
           </link-entity>
         </link-entity>
         <filter type="and" >
                  <condition attribute="customerid" operator="eq" value="{{user.contactid}}"/>
         </filter>
       </entity>
     </fetch>
      {% endfetchxml %}
      <div style='overflow-y:auto'>
        <table class="table">
          <thead><tr>
           <th>Created On</th>
           <th>Order ID</th>
           <th>Product Name</th>
           <th>Payment Method</th>
           <th>Total Amount</th>
           <th>Order Status</th>
         </tr>
         </thead>
               {% assign groups = my_query.results.entities | group_by: 'ordernumber' %}
               {% for group in groups %}
                 {% for i in group.items %}
                   {% assign paymentmethod = i.new_paymentmethod.label %}
                   {% assign totalamount = i.new_totalamount %}
                   {% assign orderstatus = i.new_orderstatus.label %}
                   {% assign createdon = i.createdon %}
                   {% assign priceperunit = i.['sod.priceperunit'] %}
                 {% endfor %}
                 <tr>
                     <td>{{ createdon | date: 'MM/dd/yyyy' }}</td>
                     <td> {{ group.key }}</td>
                     <td>
                         {% for item in group.items %}
                           {% if item.['sod.priceperunit'] > 0 %}
                               {{item.['p.name']}}<br/>
                           {% endif %}
                         {% endfor %}
                     </td>
                     <td>{{ paymentmethod }}</td>
                     <td>{{ totalamount }}</td>
                     <td>{{ orderstatus }} </td>
                 </tr>
               {% endfor %}
       </table>
       {% if groups.size < 1 %}
           There are no items to display.
       {% endif %}
     </div>


  • Community Member Profile Picture
    on at
    RE: Display result of fetchXML in ADX portal

    Thank for this

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans