2014-12-03 24 views
2

我正在嘗試編寫一個FetchXML查詢,該查詢生成一個結果集,其中包含所有沒有任何子主題的主題(或者等價地,沒有用作另一個主題的主題)。這些「葉子」主題可以出現在多級主題層次結構的任何級別,並且是用戶應該爲案例(事件)選擇的主題。將Subject層次結構摺疊爲CRM本身的單個層次是不切實際的,但使用CRM數據服務的應用程序需要有效主題列表。查詢所有沒有孩子的主題

MSDN提供了使用左外部聯接來查找未在另一個實體的引用字段中使用的記錄(例如,沒有始發線索的所有帳戶)的示例,但對於我來說,我可以不要讓它與主題一起工作。

我目前最好的嘗試是這樣的:

@"<fetch mapping='logical'> 
    <entity name='subject'> 
     <attribute name='subjectid' /> 
     <attribute name='title' /> 
     <link-entity name='subject' alias='child' from='parentsubject' to='subjectid' link-type='outer'> 
      <attribute name='subjectid' /> 
      <attribute name='title' /> 
      <filter type='and'> 
       <condition entity='child' attribute='subjectid' operator='null'/> 
      </filter> 
     </link-entity>       
     <order attribute='title' />      
    </entity> 
</fetch>" 

此查詢生成一個包含所有科目的結果集,彷彿被鏈接的實體部分不存在。

刪除過濾器會產生一些交叉連接;所有有孩子的受試者都加入到他們的每個孩子中(但沒有沒有孩子的參考資料),那麼所有沒有孩子的受試者也會出席。我只想要第二個類別,但添加過濾器以刪除有子女的主題,顯示這些主題就好像他們沒有任何子女。

幫助!

回答

1

您的示例(沒有源頭的帳戶)與您想實現的目標完全相反:在該示例中,「父級」是主管並且您正在查找沒有父級的子帳戶(帳戶) (鉛)。

CRM不支持這種類型的查詢,可悲......

一個非常粗略的方式來實現,這可能是(僞邏輯)

 
1. Fetch all subjects (let's name this list LIST1) 
2. From LIST1, pluck out the (distinct) values of parentsubjectid attributes. Let's call this LIST2 
3. From LIST1, remove all records where ID is included in LIST2 
4. LIST1 now contains all records which aren't linked as parentsubject in any record