使用Tridion Core Service的GetListUsingItems返回的项目多于TOM

时间:2012-03-01 11:49:43

标签: tridion

我希望使用Tridion Core Service的GetListUsingItems方法获取Blueprint项目的所有子项。我使用核心服务得到的结果(更多)与使用TOM中的旧方法不同。看来我还通过组件链接返回引用我的源组件的其他组件。我在核心服务中缺少过滤器选项吗?

Tridion 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

Tridion 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 个答案:

答案 0 :(得分: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