GetListUsingItems with Tridion Core Service returns more items than TOM

偶尔善良 提交于 2019-12-08 16:51:39

问题


I want to get all children of a Blueprint item using the GetListUsingItems approach with the Tridion Core Service. I get back different results (more) with the Core Service than with the old way in TOM. It appears I also get back other Components referencing my source Component via a Component Link. Am I missing a filter option in the Core Service?

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 Core Service:

   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:


You should use BluePrintChainFilterData :

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

Please note that you can specify Direction property. This filter, however will not show you shared items. Also, try to avoid using UsingItemsFilterData as it is heavy on database

If you want to include shared items as well, then you can use BluePrintFilterData:

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

You can specify ForItem property here to set your item. It will return you something like this:

<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>

The good thing about system wide list is that you can use GetSystemWideList method that will return you array of BluePrintNodeData objects instead of XML



来源:https://stackoverflow.com/questions/9515647/getlistusingitems-with-tridion-core-service-returns-more-items-than-tom

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!