Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Unanswered

Combining 2 FetchXML With Same Dataset but different filters in Linked Entities

Posted on by 60

Is it possible to combine 2 FetchXMLs, which are fetching same dataset, but different filters in their linked entities?

Below are 2 FetchXMLs that I am trying to merge to optimize performance. In green are common filters, and yellow are filters unique to it's fetchXML.

FetchXML (1)
<fetch>

  <entity name="msdyn_workorder" >
    <filter type="and" >
      <condition attribute="statecode" operator="neq" value="1" />
      <condition attribute="wo_regionname" operator="in" >@[$Project::IncludeRegion]</condition>
    </filter>
    <link-entity name="msdyn_workorderproduct" from="msdyn_workorder" to="msdyn_workorderid" link-type="inner" alias="wop" >
      <filter type="and" >
        <condition attribute="statecode" operator="neq" value="1" />
        <condition attribute="tel_wo_unknownpart" operator="neq" value="1" />
        <condition attribute="tel_wo_installedqtysubmitstatus" operator="eq" value="100000200" />
      </filter>
      <link-entity name="uom" from="uomid" to="msdyn_unit" link-type="outer" alias="uom" >
        <attribute name="name" />
      </link-entity>
      <link-entity name="tel_wo_partsubcategory" from="tel_wo_partsubcategoryid" to="tel_wo_subcategory" link-type="inner" alias="subcategory" >
        <filter type="or" >
          <condition attribute="tel_wo_code" operator="eq" value="001001" />
          <condition attribute="tel_wo_code" operator="eq" value="002002" />
        </filter>
        <link-entity name="tel_wo_partcategory" from="tel_wo_partcategoryid" to="tel_wo_partcategory" link-type="inner" alias="category" >
          <filter type="or" >
            <condition attribute="tel_wo_code" operator="eq" value="001" />
            <condition attribute="tel_wo_code" operator="eq" value="002" />
          </filter>
        </link-entity>
      </link-entity>
      <order attribute="msdyn_workorderproductid" />
    </link-entity>
    <link-entity name="tel_com_salesorderheader" from="tel_com_salesorderheaderid" to="tel_wo_primary_so" link-type="outer" alias="primaryso" >
      <attribute name="tel_com_sales_document_no" />
    </link-entity>
    <link-entity name="territory" from="territoryid" to="wo_region" link-type="inner" alias="Region" >
      <filter>
        <condition attribute="tel_com_sendcs0130afterinstalledqtychanged" operator="eq" value="1" />
      </filter>
    </link-entity>
  </entity>
</fetch>


FetchXML (2)

<fetch>
  <entity name="msdyn_workorder" >
    <filter type="and" >
      <condition attribute="msdyn_timeclosed" operator="not-null" />
      <condition attribute="tel_wo_trigger_installedparts_integration" operator="eq" value="1" />
      <condition attribute="statecode" operator="neq" value="1" />
      <condition attribute="wo_regionname" operator="in" >@[$Project::IncludeRegion]</condition>
    </filter>
    <link-entity name="msdyn_workorderproduct" from="msdyn_workorder" to="msdyn_workorderid" link-type="inner" alias="wop" >
      <filter type="and" >
        <condition attribute="statecode" operator="neq" value="1" />
        <condition attribute="tel_wo_unknownpart" operator="neq" value="1" />
      </filter>
      <link-entity name="uom" from="uomid" to="msdyn_unit" link-type="outer" alias="uom" >
        <attribute name="name" />
      </link-entity>
      <link-entity name="tel_wo_partsubcategory" from="tel_wo_partsubcategoryid" to="tel_wo_subcategory" link-type="inner" alias="subcategory" >
        <attribute name="tel_wo_code" />
        <filter type="or" >
          <condition attribute="tel_wo_code" operator="eq" value="001001" />
          <condition attribute="tel_wo_code" operator="eq" value="001002" />
          <condition attribute="tel_wo_code" operator="eq" value="002001" />
          <condition attribute="tel_wo_code" operator="eq" value="002002" />
          <condition attribute="tel_wo_code" operator="eq" value="002003" />
          <condition attribute="tel_wo_code" operator="eq" value="004004" />
        </filter>
        <link-entity name="tel_wo_partcategory" from="tel_wo_partcategoryid" to="tel_wo_partcategory" link-type="inner" alias="category" >
          <attribute name="tel_wo_code" />
          <filter type="or" >
            <condition attribute="tel_wo_code" operator="eq" value="001" />
            <condition attribute="tel_wo_code" operator="eq" value="002" />
            <condition attribute="tel_wo_code" operator="eq" value="004" />
          </filter>
        </link-entity>
      </link-entity>
      <order attribute="msdyn_workorderproductid" />
    </link-entity>
    <link-entity name="tel_com_salesorderheader" from="tel_com_salesorderheaderid" to="tel_wo_primary_so" link-type="outer" alias="primaryso" >
      <attribute name="tel_com_sales_document_no" />
    </link-entity>
    <link-entity name="territory" from="territoryid" to="wo_region" link-type="inner" alias="Region" >
      <attribute name="tel_com_sendcs0130afterinstalledqtychanged" />
    </link-entity>
  </entity>
</fetch>

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