locked
fetchXml : retrieve results of 2 fetchXMl in One subgrid RRS feed

  • Question

  • Hello,

    I explain my problem to you and hope that someone can help me. Here I have 3 tables in my database

    contactssalesordersbeneficiaries 

    -contacts and salesorders are connected by a relation Party 1-> N sales orders. The PK is salesorder_id and the FK in salesorders is contactHolder.

    - salesorders et beneficiaries are connected by a relation salesorders 1-> N beneficiaries. The PK is not useful but the FK in beneficiaries is b_salesorders_id 

    - contacts et beneficiaries are connected by a relation contacts 1-> N beneficiaries. The PK is not useful but the FK in   beneficiaries is b_contacts_id 

    I would like retrieve all contacts having  the id value of salesorders but I must verify in the 2 others tables salesorders and beneficiaries . So , if the value that is searched is found in the table benefiaries OR in the table saleorders, we retrieve the contact that will be displayed in a sub-grid?

    So I do fetch XML : 

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
      <entity name="contact">
        <attribute name="fullname" />
        <attribute name="telephone1" />
        <attribute name="emailaddress1" />
        <attribute name="address1_city" />
        <attribute name="address1_postalcode" />
        <attribute name="language" />
        <attribute name="contactid" />
        <order attribute="fullname" descending="false" />
        <filter type="and">
          <condition attribute="city" operator="like" value="%brussel%" />
        </filter>
        <link-entity name="salesorders" from="contactholder" to="contactid" alias="ac">
          <filter type="and">
            <condition attribute="salesorders_id" operator="eq" value="1629240001" />
          </filter>
        </link-entity>
        <link-entity name="beneficiaries" from="b_contacts_id " to="contactid" alias="af">
          <filter type="and">
            <condition attribute="b_salesorders_id " operator="eq" value="1629240001"" />
          </filter>
        </link-entity>
      </entity>
    </fetch>

    I would like to do an OR filter between the link-entity. Is it possible ? Because by default, it is an AND filter.

    Is it possible to add the results of 2 fetch XML executions in 1 sub-grid?

    Thank you in advance for your answers.

    Yours,

    Az.

    Monday, November 21, 2016 8:43 AM

All replies

  • Hello,

    I'm really sorry but you can't do that.


    Dynamics CRM MVP
    Read My blog
    Subscribe for one of my courses

    Monday, November 21, 2016 11:33 AM
    Moderator
  • Thanks for you answer. But it's possible to do this with an other way ?
    Monday, November 21, 2016 11:40 AM
  • First way I see is following:

    1. Create an Action that returns EntityCollection as result.

    2. Develop a plugin that will handle your new Action's message and populate the collection with results you need.

    3. Develop a webresource that will display with results of execution of call of your new Action.

    Second way:

    1. Add some special field to contact entity that will mean that one of link-entity conditions is met.

    2. Develop a plugin that will handle CRUD operations with salesorders/beneficiaries and populate that field created on step1.

    3. Use field created in step 1 instead of link-entities in your fetchxml query.


    Dynamics CRM MVP
    Read My blog
    Subscribe for one of my courses

    Monday, November 21, 2016 11:49 AM
    Moderator
  • You cannot add OR operator with linked entity.

    You cannot union two fetchxml.

    You can think of creating an html web resource. Fetch data from both the entities and create a table. Then show the web resource in an iframe. You can pass parameters to the iframe also.

    Try creating a report instead of iframe


    Regards Faisal


    • Edited by Faisal Fiaz Wednesday, November 23, 2016 1:20 PM
    Wednesday, November 23, 2016 1:12 PM