6

I get the list of parent publications from child using the below snippet

var pubData = (PublicationData)client.Read("tcm:0-3702-1", new ReadOptions());
foreach (var parent in pubData.Parents)
{
    string parentUri = parent.IdRef;
}

Now I need to get the list of child publications from parent publication. Is there any way to obtain this?

4 Answers 4

4

"Where Used" is your friend here.

client.GetList(publicationId, new UsingItemsFilterData());

will return you a list of items which "use" the publication, i.e. it's children.

The list will include all of the descendant publications. If you want only the direct children then you can loop over each publication in the list and check it's parents - Something like:

var descendantPublications = client.GetList(publicationId, new UsingItemsFilterData());

var childPublications = new List<IdentifiableObjectData>();

foreach (var identifiableObject in descendantPublications)
{
    var publication = (PublicationData)client.Read(identifiableObject.Id, null);
    if (publication.Parents.Select(p => p.IdRef).Contains(publicationId))
    {
        childPublications.Add(identifiableObject);
    }
}
3

I think the solution you need is outlined here: https://stackoverflow.com/questions/9515647/getlistusingitems-with-tridion-core-service-returns-more-items-than-tom

Copied here to have the data within this website:

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

3
  • Hi John, I tried BluePrintChainFilterData earlier but this doesn't work on publications.it works on components,pages etc.
    – Sam
    Commented Mar 24, 2014 at 12:03
  • 2
    Be smart. Each publication has a RootFolder property. Do it for root folders, it will give you pretty much the same result as there are no publications without folders. You can then get publications by looking at tcm:BluePrintNode attributes Commented Mar 24, 2014 at 12:15
  • 1
    As you know all the root structure groups are inherited from the main parent and so all these are shared items.So if i try to get the list it gives me the complete publication list instead of just mentioning the exact blue print.Also if i try it on a localized root SG it returns only one node which is the current publication.
    – Sam
    Commented Mar 25, 2014 at 4:49
1

Well of course, the easy answer is that if you can get the parents, then listing the children is just a matter of programming.

As I recall, there isn't a particularly obvious way to get a list of children. You can perhaps use BluePrintNodesFilterData, but you'll still have some work to do.

It depends on what you are trying to do. I recall once trying to construct lists of children, only to discover that ICoreService2013.ResolveItems gave me a more direct route to my intended result.

1

I suggest retrieving a full list of publications and then looping through it, checking if each one has the requested publication as a parent:

List<PublicationData> PublicationList = LoadPublications();

// Retrieve a list of all publications, adding each as a publication type so that the properties
// can be more easily read
private void LoadPublications()
{
    // Note: retrieving list of publication data using GetAllPublicationData.GetAllPublicationData()
    // does not work as the returned elements contain null PublicationPaths; thus, the 
    // following procedure is used instead:
    if (PublicationList == null || PublicationList.Count == 0)
    {
        PublicationList = new List<PublicationData>();
        PublicationsFilterData filter = new PublicationsFilterData();
        XElement publications = tridionClient.ClientInstance.GetSystemWideListXml(filter);
        PublicationData pubItem;
        foreach (XElement itemElem in publications.Descendants())
        {
            pubItem = (PublicationData)tridionClient.ClientInstance.Read(itemElem.Attribute("ID").Value, new ReadOptions());
            PublicationList.Add(pubItem);
        }
    }
}


// Construct a list of publications that, in the blueprint, are children of the current publication
private List<PublicationData> Children(PublicationData parentPublication = null)
{
    // Initialize the working variables
    List<PublicationData> childPublications = new List<PublicationData>();

    // Loop through all of the publications
    // For each publication that has this one as a parent, add it to the list
    if (parentPublication != null)
    {
        foreach (PublicationData childPublication in PublicationList)
        {
            if (childPublication.Parents != null)
            {
                foreach (LinkToRepositoryData checkParentPublication in childPublication.Parents)
                {
                    if (parentPublication.Id == checkParentPublication.IdRef)
                    {
                        childPublications.Add(childPublication);
                    }
                }
            }
        }
    }

    // Return either the full list or the empt list
    return childPublications;
}
1
  • Or use linq: PublicationList.Where(pub => pub.Parents.Any(parent => parent.Id == checkParentPublication.IdRef)); Commented Jul 23, 2015 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.