Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get child structure groups given a structure group TCM URI with Core Service

How can I get all child structure groups given a structure group TCM URI with Core Service?

I tried using this code:

ItemsFilterData sgFilter = new RepositoryItemsFilterData 
    { ItemTypes = new[] { ItemType.StructureGroup }, 
      Recursive = true, 
      BaseColumns = ListBaseColumns.Id };

XElement listXml;

using (CoreServiceClient client = _coreServiceProvider.GetCoreServiceClient())
{
    listXml = XElement.Parse(
              client.ProxyClient.GetListXml(structureGroupUri, sgFilter)
              .OuterXml);
}

But I got an error saying "Unexpected item type: StructureGroup".

like image 623
Andreas Nellmon Avatar asked Nov 05 '12 17:11

Andreas Nellmon


1 Answers

Starting from the Publication's URI, this works:

client.GetListXml("tcm:0-10-1", new RepositoryItemsFilterData { 
    ItemTypes = new[] { ItemType.StructureGroup }, 
    Recursive = true, 
    BaseColumns = ListBaseColumns.Id 
})

The trick is always to find the correct filter type, which in this case is RepositoryItemsFilterData.

Non-working sample

Starting from the Structure Group's URI, this returns the direct children Structure Groups. Note that that Recursive = true seems to be ignored here.

client.GetListXml("tcm:10-328-4", new OrganizationalItemItemsFilterData { 
    ItemTypes = new[] { ItemType.StructureGroup }, 
    Recursive = true, 
    BaseColumns = ListBaseColumns.Id 
})
like image 187
Frank van Puffelen Avatar answered Oct 13 '22 09:10

Frank van Puffelen