Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Display result of fetchXML in ADX portal

Posted on by Microsoft Employee
{% 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

  • RE: Display result of fetchXML in ADX portal

    where I can add this code?

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

    You can achieve that with group_by. This is my working code:

    {% fetchxml feed %}
    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" count="10" returntotalrecordcount="true" {% if request.params['page'] %} page="{{request.params['page']}}" {% else %} page="1" {% endif %}>
    <entity name="cool_courseoutline">
    <attribute name="cool_courseoutlineid" />
    <attribute name="cool_simsid" />
    <attribute name="cool_coursecode" />
    <attribute name="cool_coursename" />
    <attribute name="cool_schoolname" />
    <attribute name="cool_schoolnameshort" />
    <attribute name="cool_staffinfo" />
    <order attribute="cool_simsid" descending="false" />
    <link-entity name="cool_assessment" from="cool_courseoutlineid" to="cool_courseoutlineid" alias="assessment" type="inner">
    <attribute name="cool_courseoutlineid" />
    <attribute name="cool_task" />
    <attribute name="cool_weighting" />
    <attribute name="cool_length" />
    <attribute name="cool_duedate" />
    </link-entity>
    </entity>
    </fetch>
    {% endfetchxml %}
    {% assign courses = feed.results.entities | group_by: 'cool_simsid' %}
    {
    "courseoutlines": [
    {% for c in courses %}
    { {% for i in c.items %}
    {% unless forloop.index0 > 0 %}
    "simsid": "{{ i.cool_simsid }}",
    "coursecode": "{{ i.cool_coursecode }}",
    "coursename": "{{ i.cool_coursename }}",
    "schoolname": "{{ i.cool_schoolname }}",
    "schoolnameshort": "{{ i.cool_schoolnameshort }}"
    "assessments": [ {% for item in c.items %}
    {"task": {{item.['assessment.cool_task']}},
    "weighting": {{item.['assessment.cool_weighting']}},
    "length": {{item.['assessment.cool_length']}},
    "duedate": {{item.['assessment.cool_duedate']}}}{% unless forloop.last %},{% endunless %}
    {% endfor %} ]
    {% endunless %}{% endfor %}}
    {% unless forloop.last %},{% endunless %}{% endfor %}]
    }

  • Suggested answer
    Arpit Shrivastava Profile Picture
    Arpit Shrivastava 7,518 User Group Leader on at
    RE: Display result of fetchXML in ADX portal

    Hi Arthur,

    My issue is still there on 7.20 version of Adxstudio. but i tried on other environment which is on 7.24 version and i am not facing any issue. Its working fine.

    As per my investigation -

    My Adxstudio visual studio solution is still on 7.20 ver. But in my crm instance, adxstudio solution has automatically been upgraded to 7.25 ver that is the latest ver.since it is online so Microsoft has did it itself. But i didn' upgrade my visual studio solution.

    So expecting, due to this clash i am facing this issue.

    But on working environment, my crm Adxstudio solution and visual studio solution both are on 7.25 version. So its working fine.

    Hope it may help you too.

    Cheers

    Arpit

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Display result of fetchXML in ADX portal

    Hi,

      this thread mentions 8.0+ - it might be when fetchXml tag was introduced:

    community.adxstudio.com/.../68465eea-2806-e611-9407-000d3a10c65c

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

    Hello Arpit,

    I'm facing the exact same issue, what is your ADX Portal version ?

    I was working on Portal 8.3.0.215 before and everything worked perfectly, but now I have a project on Adxstudio Portals 7.0.21.0 and "Unknown tag 'fetchxml'" shows up on my screen.

    If anyone has a solution about this issue, that'd be more than welcomed !

    Thanks in advance for your help.

    Arthur

  • Arpit Shrivastava Profile Picture
    Arpit Shrivastava 7,518 User Group Leader on at
    RE: Display result of fetchXML in ADX portal

    Hi Ruzel,

    I am facing "Unknown tag 'fetchxml'" error message while running below Fetch XML:

    {% fetchxml my_query%}

     <entity name="contact">

       <attribute name="fullname" />

       <attribute name="telephone1" />

       <attribute name="contactid" />

       <attribute name="emailaddress2" />

       <order attribute="fullname" descending="false" />

       <filter type="and">

       <condition attribute="emailaddress2" operator="like" value="%arpit@gmail.com%" />

       </filter>

     </entity>

    {% endfetchxml %}

    I am having 'Global' entity permissions on Contact Entity. Any suggestion ?

    Previously It was working fine. Started getting this issue from last 2-3 days.

    Thanks in advance.

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

    Thank for this

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee 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
    Community Member Microsoft Employee 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 ?

  • Suggested answer
    duchan Profile Picture
    duchan 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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans