英文:
Combining 2 FetchXML With Same Dataset but different filters in Linked Entities
问题
以下是要翻译的内容:
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>
英文:
Is it possible to combine 2 FetchXMLs, which are fetching same data, but different filters in linked entities?
Below are 2 FetchXMLs that I am trying to merge to optimize performance. I marked each filter condition as //common
or //unique
to each query.
> FetchXML (1)
<fetch>
<entity name="msdyn_workorder" >
<filter type="and" >
<condition attribute="statecode" operator="neq" value="1" /> //Common
<condition attribute="wo_regionname" operator="in" >@[$Project::IncludeRegion]</condition> //Common
</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" /> //Common
<condition attribute="tel_wo_unknownpart" operator="neq" value="1" /> //Common
<condition attribute="tel_wo_installedqtysubmitstatus" operator="eq" value="100000200" /> //Unique
</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" /> //Common
<condition attribute="tel_wo_code" operator="eq" value="002002" /> //Common
</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" /> //Common
<condition attribute="tel_wo_code" operator="eq" value="002" /> //Common
</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" /> //Unique
</filter>
</link-entity>
</entity>
</fetch>
> FetchXML (2)
<fetch>
<entity name="msdyn_workorder" >
<filter type="and" >
<condition attribute="msdyn_timeclosed" operator="not-null" /> //Unique
<condition attribute="tel_wo_trigger_installedparts_integration" operator="eq" value="1" /> //Unique
<condition attribute="statecode" operator="neq" value="1" /> //Common
<condition attribute="wo_regionname" operator="in" >@[$Project::IncludeRegion]</condition> //Common
</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" /> //Common
<condition attribute="tel_wo_unknownpart" operator="neq" value="1" /> //Common
</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" /> //Common
<condition attribute="tel_wo_code" operator="eq" value="001002" /> //Common
<condition attribute="tel_wo_code" operator="eq" value="002001" /> //Unique
<condition attribute="tel_wo_code" operator="eq" value="002002" /> //Unique
<condition attribute="tel_wo_code" operator="eq" value="002003" /> //Unique
<condition attribute="tel_wo_code" operator="eq" value="004004" /> //Unique
</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" /> //Common
<condition attribute="tel_wo_code" operator="eq" value="002" /> //Common
<condition attribute="tel_wo_code" operator="eq" value="004" /> //Unique
</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>
答案1
得分: 0
以下是翻译好的部分:
<?xml version="1.0" encoding="UTF-8"?>
<fetch>
<entity name="msdyn_workorder">
<attribute name="msdyn_timeclosed" />
<attribute name="tel_wo_trigger_installedparts_integration" />
<filter type="and">
<condition attribute="statecode" operator="neq" value="1" />
<condition attribute="wo_regionname" operator="in" />
</filter>
<link-entity name="msdyn_workorderproduct" from="msdyn_workorder" to="msdyn_workorderid" link-type="inner" alias="wop">
<attribute name="tel_wo_installedqtysubmitstatus" />
<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>
英文:
The best way to converge both fetchxml is below. Basically I did following things
-
Removed all unique conditions and added attributes for every condition. Once you retrieve you can filter it later in the entity collection
-
Combined all condition attributes in filter or condition together, this should again be filtered in entity collection via code
<?xml version="1.0" encoding="UTF-8"?>
<fetch>
<entity name="msdyn_workorder">
<attribute name="msdyn_timeclosed" />
<attribute name="tel_wo_trigger_installedparts_integration" />
<filter type="and">
<condition attribute="statecode" operator="neq" value="1" />
<condition attribute="wo_regionname" operator="in" />
</filter>
<link-entity name="msdyn_workorderproduct" from="msdyn_workorder" to="msdyn_workorderid" link-type="inner" alias="wop">
<attribute name="tel_wo_installedqtysubmitstatus" />
<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>
答案2
得分: 0
合并这些FetchXML查询需要类似于SQL UNION的结构,不幸的是,FetchXML不支持此功能。
有两个选项:
- 保持这些查询分开。
- 创建一个查询,选择比实际需要的行稍多,并在之后筛选结果。
英文:
Merging these FetchXML queries would require an SQL UNION like construction and unfortunately this is not supported by FetchXML.
There are two options:
- Keep these queries separate.
- Create one query selecting slightly more rows than actually needed and filter the results afterwards.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论