2012-03-01 54 views
8

我想使用GetListUsingItems方法和Tridion核心服務獲取Blueprint項目的所有子項。與TOM中的舊方式相比,使用Core Service獲得不同的結果(更多)。看來我也通過一個Component Link取回了引用我的源組件的其他組件。我是否缺少核心服務中的過濾器選項?使用Tridion核心服務的GetListUsingItems返回的項目多於TOM

外表套上5.3:

Function GetLocalizedItemNodes(itemUri) 
    Dim tridionItem : set tridionItem = tdse.GetObject(itemUri,1) 
    Dim rowFilter : set rowFilter = tdse.CreateListRowFilter() 
    call rowFilter.SetCondition("ItemType", GetItemType(itemUri)) 
    call rowFilter.SetCondition("InclLocalCopies", true) 
    Dim usingItemsXml : usingItemsXml = tridionItem.Info.GetListUsingItems(1919, rowFilter) 

    Dim domDoc : set domDoc = GetNewDOMDocument() 
    domDoc.LoadXml(usingItemsXml) 
    Dim nodeList : set nodeList = domDoc.SelectNodes("/tcm:ListUsingItems/tcm:Item[@CommentToken='LocalCopy']") 

    set tridionItem = nothing 
    set domDoc = nothing 
    set GetLocalizedItemNodes = nodeList 
End Function 

外表套上2011 SP1核心服務:

private XElement GetLocalizedItems(string itemUri) 
    { 
     XElement usingXML = null; 
     try 
     { 
      CoreServiceClient client = new CoreServiceClient(); 
      client.ClientCredentials.Windows.ClientCredential.UserName = ConfigurationManager.AppSettings["impersonationUser"].ToString(); // "administrator"; 
      client.ClientCredentials.Windows.ClientCredential.Password = ConfigurationManager.AppSettings["impersonationPassword"].ToString(); 
      client.ClientCredentials.Windows.ClientCredential.Domain = ConfigurationManager.AppSettings["impersonationDomain"].ToString(); 

      // original code from http://www.tridiondeveloper.com/getting-used-items-using-the-core-service 
      // Create a filter 
      UsingItemsFilterData usingItemsFilterData = new UsingItemsFilterData 
      { 
       BaseColumns = ListBaseColumns.IdAndTitle, // to specify the detail in the XML 
       IncludeLocalCopies = true, 
       ItemTypes = new[] { ItemType.Component } 
      }; 
      // Get the XML by calling .GetListXml on the client (assumes you have a 'client' object already) 
      usingXML = client.GetListXml(itemUri, usingItemsFilterData); 

     } 
     catch (Exception ex) 
     { 
      throw; 
     } 
     return usingXML; 
    } 
+1

羅伯特嗨的陣列。它不應該影響你回來的組件的數量(因爲你的源項目是一個組件),但值得注意的是你的R5.3代碼設置了一個'ItemType'行過濾器(這意味着你將只獲得組件回來),但你的核心服務代碼不。這可能會影響您的結果總數,但不會影響組件的數量(如您所描述的那樣)。 – 2012-03-01 12:13:42

+0

我添加了ItemTypes條件,但仍然得到相關的組件和子項。任何其他想法? – robrtc 2012-03-01 12:39:11

回答

6

您應該使用BluePrintChainFilterData

BluePrintChainFilterData filter = new BluePrintChainFilterData(); 
filter.Direction = BluePrintChainDirection.Down; 
var result = ClientAdmin.GetListXml("tcm:3-1905", filter); 

請注意,您可以指定方向財產。但是這個過濾器不會顯示你共享的項目。另外,儘量避免使用UsingItemsFilterData,因爲它是數據庫

如果你想,包括共享項目以及重,那麼你可以使用BluePrintFilterData

BluePrintFilterData filter = new BluePrintFilterData(); 
filter.ForItem = new LinkToRepositoryLocalObjectData{ IdRef = "tcm:3-1905"}; 
var listXml = ClientAdmin.GetSystemWideListXml(filter); 
var list = ClientAdmin.GetSystemWideList(filter); 

您可以在這裏指定ForItem財產設置您的項目。它會回報你是這樣的:

<tcm:ListBluePrintNodes Managed="1" xmlns:tcm="http://www.tridion.com/ContentManager/5.0" xmlns:xlink="http://www.w3.org/1999/xlink"> 
    <tcm:BluePrintNode ID="tcm:0-3-1" Title="Test" Icon="T1L0P0"> 
    <tcm:Item ID="tcm:3-1905" Title="Test multimedia component" ItemType="16" IsShared="False" IsLocalized="False" IsPublished="False" LockType="0" LockUser="tcm:0-0-0" Icon="T16L0P0Mgif"></tcm:Item> 
    </tcm:BluePrintNode> 
    <tcm:BluePrintNode ID="tcm:0-172-1" Title="test_child" Icon="T1L0P0"> 
    <tcm:Parents> 
     <tcm:Parent xlink:href="tcm:0-3-1" xlink:title="Test" Priority="1"></tcm:Parent> 
    </tcm:Parents> 
    <tcm:Item ID="tcm:172-1905" Title="Test multimedia component" ItemType="16" IsShared="True" IsLocalized="False" IsPublished="False" LockType="0" LockUser="tcm:0-0-0" Icon="T16L0P0Mgif"></tcm:Item> 
    </tcm:BluePrintNode> 
</tcm:ListBluePrintNodes> 

有關係統範圍內的清單的好處是,你可以使用GetSystemWideList方法將返回BluePrintNodeData對象而不是XML

+0

太棒了!感謝您提供2個示例和很好的解釋。 – robrtc 2012-03-01 16:45:24

相關問題