Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Liquid, How to filtering lookup field in fetchxml

Posted on by Microsoft Employee
Bellow the follow code.
{% assign contactId = user.contactid %}
{% fetchxml myentity_Query %}
<fetch version="1.0" mapping="logical">
<entity name="myentity">
<attribute name="myentitytext" />
<attribute name="myentity_contactid" />
<link-entity name="contact" to="myentity_contactid" >
<filter type="and">
<condition attribute="contactid" operator="eq" value="{{ contactId }}" />
</filter>
</link-entity>
</entity>
</fetch>
{% endfetchxml %}
myentity (many to one) contact
use
myentity_contactid link contactid
contactid field is contact entity's primary key.
I cannot load the result with the follow code.
{% for item in myentity_Query.results.entities %}
<div class="item">
{{ item.myentitytext}}
</div>
{% endfor %}

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Liquid, How to filtering lookup field in fetchxml

    Hi Arpit,

    using your code the outcome of alert('{{ result.ticketnumber}}'); is written beneath the rest of my entityform. This already works. There are just those records displayed, which I want to be there.

    What I´m trying to achieve is:

    Apply this filter to a lookup field.

    Right now when I open the lookup field "parentaccount" I can see every account saved in the crm. I want to set this fetchxml filter here, so that I can only see the accounts which i filtered in the fetchxml.

    How can I achieve this?

    Greetings

    Roman

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Liquid, How to filtering lookup field in fetchxml

    Hi Arpit,

    Thanks for your help.

  • Verified answer
    Arpit Shrivastava Profile Picture
    Arpit Shrivastava 7,518 User Group Leader on at
    RE: Liquid, How to filtering lookup field in fetchxml

    Hi Evan,

    Here is the correct format to fetch data using lookup condition.

    For Demonstration, I have fetched all the Cases whose Customer is 'Arpit Shrivastava'

    {% assign contactId = user.contactid %}

    {% fetchxml my_query %}

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">

      <entity name="incident">

        <attribute name="title" />

        <attribute name="ticketnumber" />

        <attribute name="createdon" />

        <attribute name="incidentid" />

        <attribute name="caseorigincode" />

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

        <filter type="and">

          <condition attribute="customerid" operator="eq" uiname="Arpit Shrivastava" uitype="contact" value="{{ contactId }}" />

        </filter>

      </entity>

    </fetch>

    {% endfetchxml %}

    {% for result in my_query.results.entities %}

    <script type="text/javascript">

    alert('{{ result.ticketnumber}}');

    </script>

      {{ result.ticketnumber | escape }}

    {% endfor %}

    Hope it helps,

    If my answer helped to resolve your issue, kindly verify it by clicking 'Yes'. It would be helpful to the other community members seeking to resolve a similar issue.

     

    Cheers

    Arpit

    https://arpitmscrmhunt.blogspot.in

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans