cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Filter FetchXML

Hi all,

I have two entities called "Data" and "Receiver". I have lookup column in Receiver. 
Data Entity
   Record     

   2              

   3

 

Receiver Entity

Contact Lookup   Data Lookup 
Ram                    2

Sham                 2
Ron                   3

Harry                4

Amit                 10

 

I want to based on logged in user- suppose in this case logged in user is Ram then I want to all the records from Data entity which has receiver as "Ram"(crux is for that data record I want all the other receiver as well).

In above case I want record 2 from Data entity and,  Ram and Sham as receiver.

Something like this-

{

Record-2

Receiver1-Ram,

Receiver2-Sham

}


How can I do that using fetchXML?

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Anonymous,

Your code looks a little confused:

  1. You've moved the "descending" attribute of the order tag to the link-entity tag name attribute
  2. Your link entities aren't mapping correctly - the schema maps should be flipped from the first to the second
  3. Your query is "dataQuery", but your results are on "feed"

Try the below:

{% if user %}
{% fetchxml feed %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="cr579_tmf_receiver">
<attribute name="cr579_tmf_receiverid" />
<attribute name="cr579_receiver" />
<attribute name="cr579_datarequestlookup" />
<attribute name="createdon" />

<order attribute="createdon" descending="false" />
<link-entity name="cr579_tmf_datarequest" from="cr579_tmf_datarequestid" to="cr579_datarequestlookup" link-type="inner" alias="ac">
<link-entity name="cr579_tmf_receiver" from="cr579_datarequestlookup" to="cr579_tmf_datarequestid" link-type="inner" alias="ad">
<filter type="and">
<condition attribute="cr579_receiver" operator="eq" value="{{ user.contactid }}" />
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>
{% endfetchxml %}


{% for item in feed.results.entities %}
{
"ReceiverName": "{{ item.cr579_receiver.name }}",
"DataReuqestName": "{{ item.cr579_datarequestlookup.name }}",


}{% unless forloop.last %},{% endunless %}
{% endfor %}

{% endif %}

View solution in original post

5 REPLIES 5
OOlashyn
Super User
Super User

Hi @Anonymous,

I think you will need to perform at least two fetchxml requests. In first you can get a list of all of receiver entities (with data field value) where contact is your current user. Then you would need to go through each receiver record and based on the data value perform next query to get receivers filtered by data.

----------------------------------------------------
If you find this post helpful consider marking it as a solution to help others find it.
justinburch
Microsoft
Microsoft

Hi @Anonymous,

Consider the following pseudocode.

{% if user %}
  {% fetchxml dataQuery %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
  <entity name="jb_receiver">
    <attribute name="jb_receiverid" />
    <attribute name="jb_name" />
    <attribute name="createdon" />
    <order attribute="jb_name" descending="false" />
    <link-entity name="jb_data" from="jb_dataid" to="jb_dataid" link-type="inner" alias="ac">
      <link-entity name="jb_receiver" from="jb_dataid" to="jb_dataid" link-type="inner" alias="ad">
        <filter type="and">
          <condition attribute="jb_contactid" operator="eq" value="{{ user.contactid }}" />
        </filter>
      </link-entity>
    </link-entity>
  </entity>
</fetch>
  {% endfetchxml %}
  {% for dataResult in dataQuery %}
    .. list HTML objects, JSON response, JS variable assignment, whatever your representation is
  {% endfor %}
{% endif %}

My Data:

justinburch_0-1612472093999.png

My Results when searching on UserA:

justinburch_1-1612472132079.png

Test it thoroughly. 🙂 I did it in haste and trust @OOlashyn enough to assume it might require two queries based on his initial feedback.

Anonymous
Not applicable

Hi @OOlashyn,
okay will try that       

Anonymous
Not applicable

Can you please elaborate on the <link - entity> part?

{% if user %}
{% fetchxml dataQuery %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="cr579_tmf_receiver">
<attribute name="cr579_tmf_receiverid" />
<attribute name="cr579_receiver" />
<attribute name="cr579_datarequestlookup" />
<attribute name="createdon" />

<order attribute="createdon" ="false" />
<link-entity namedescending="cr579_tmf_datarequest" from="cr579_tmf_datarequestid" to="cr579_datarequestlookup" link-type="inner" alias="ac">
<link-entity name="cr579_tmf_receiver" from="cr579_receiver" to="contactid" link-type="inner" alias="ad">
<filter type="and">
<condition attribute="cr579_receiver" operator="eq" value="{{ user.contactid }}" />
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>
{% endfetchxml %}


{% for item in feed.results.entities %}
{
"ReceiverName": "{{ item.cr579_receiver.name }}",
"DataReuqestName": "{{ item.cr579_datarequestlookup.name }}",


}{% unless forloop.last %},{% endunless %}
{% endfor %}

{% endif %}

this code is not working

Hi @Anonymous,

Your code looks a little confused:

  1. You've moved the "descending" attribute of the order tag to the link-entity tag name attribute
  2. Your link entities aren't mapping correctly - the schema maps should be flipped from the first to the second
  3. Your query is "dataQuery", but your results are on "feed"

Try the below:

{% if user %}
{% fetchxml feed %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="cr579_tmf_receiver">
<attribute name="cr579_tmf_receiverid" />
<attribute name="cr579_receiver" />
<attribute name="cr579_datarequestlookup" />
<attribute name="createdon" />

<order attribute="createdon" descending="false" />
<link-entity name="cr579_tmf_datarequest" from="cr579_tmf_datarequestid" to="cr579_datarequestlookup" link-type="inner" alias="ac">
<link-entity name="cr579_tmf_receiver" from="cr579_datarequestlookup" to="cr579_tmf_datarequestid" link-type="inner" alias="ad">
<filter type="and">
<condition attribute="cr579_receiver" operator="eq" value="{{ user.contactid }}" />
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>
{% endfetchxml %}


{% for item in feed.results.entities %}
{
"ReceiverName": "{{ item.cr579_receiver.name }}",
"DataReuqestName": "{{ item.cr579_datarequestlookup.name }}",


}{% unless forloop.last %},{% endunless %}
{% endfor %}

{% endif %}

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Carousel News & Announcements 768460.png

What's New in the Community?

Check out the latest News & Events in the community!

MPP IDEAS updated 768x460.png

Ideas

Discover ideas and concepts from users like you for how to use Power Pages and take your work to the next level.

Users online (3,354)