Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetListUsingItems with Tridion Core Service returns more items than TOM

Tags:

tridion

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;
    }
like image 811
robrtc Avatar asked Mar 01 '12 11:03

robrtc


1 Answers

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

like image 161
Andrey Marchuk Avatar answered Nov 13 '22 14:11

Andrey Marchuk