1

I have a parent publication "A", where a category is created. Now several child publications are inherited from this parent publication A: keywords can be created in any of these child Publications.

What is the best approach to get a list of all keywords in the category, no matter in which Publication they are created? My starting point is the uri of the category in the Parent Publication (A), I have NO Publication context.

I'd prefer to get this solved with TOM.NET. Any ideas on the most optimal approach?


Some more backgrouund info: As part of an integration, keywords are automatically created (representing IDs on the system we integrate with). The keywords are created in the child Publications where the Components (that use this ID) are created.

I would like to have this list of all keywords to:

  • Report (and automatically remove) unused keywords
  • Easily query on this custom ID on the CMS (without using search !)

Based on your comments, this is the most optimized way to get all keywords in all Blueprinted categories. A bit more work is required to get it all in a joined list, but this works for me now.

Tridion.ContentManager.Session session = new Tridion.ContentManager.Session(User.Identity.Name);
Category parentCat = (Category)session.GetObject(categoryWebdavUrl);

SystemManager systemManager = session.SystemManager;
BluePrintFilter bf = new BluePrintFilter(session)
{
    BaseColumns = ListBaseColumns.Id,
    ForItem = parentCat
};

foreach (BluePrintNode node in systemManager.GetBluePrintNodes(bf))
{
    var item = node.Item;
    if (item is Category)
    {
        Category cat = (Category)item;
        foreach (Keyword keyw in cat.GetKeywords())
        {
            try
            {
                // Perform magic here
            }
            catch { }
        }
    }
}
1
  • 2
    Please share what you've tried already and the specific issue you ran into. Dec 2, 2014 at 17:15

3 Answers 3

4

this post has some useful bits on finding child publications of a context publication.

Finding all keywords in the category
Category items have a GetKeywords() method which should return all keywords in the category. On top of that you would have to enumerate all child publications of the publication in which the category originates and then union the results (.Net Linq is very helpful here).

Finding all instances of the category in the blueprint children
From what I read in the TOM.NET api docs for 2011SP1 the following should work:

SystemManager systemManager = session.SystemManager;
BluePrintNodesFilter filter = new BluePrintNodesFilter(session)
{
  BaseColumns = ListBaseColumns.Id,
  ForItem = yourCategory
};
IEnumerable<BluePrintNode> allNodes = systemManager.GetBluePrintNodes(filter);
1
  • BluePrintNodesFilter does not exist in 2011, as it is intriduced with 2013. BluePrintFilter does the trick in 2011. Works like a charm ! Dec 5, 2014 at 15:49
1

The problem here is more related to your BluePrint than the Category and its Keywords. OrganizationalItem.GetItems() is designed to return a list of repository-local objects, so from the parent Publication that is useless to you (that doesn't change with filters you can supply).

So if your BluePrint is linear, your best bet would be to start from the lowest Publication, and do a OrganizationalItem.GetItems() from there. But that means you first need to get a clear view on your BluePrint and find your lowest point. In case your BluePrint is not linear, you will have to get the items from each end point of your BluePrint chain and combine those into a single list.

Good question, for which I don't see a simple solution unfortunately. Since I can't give you a "solution" answer, maybe I should ask a question on why you have this requirement? Perhaps that can give us more insight in providing an alternate answer.

1

I can imagine a few solutions:

  • As already mentioned by Bjorn: get all Repositories in the BluePrint using GetBluePrintNodes, iterate over them and call Category.GetKeywords in each context Repository
  • As already mentioned by Bart: call Category.GetKeyword (or .GetItems) in context of the lowest point in the BluePrint. If you don't have a single lowest point, you could consider creating it for this purpose: create a new child Repository that has all your current BluePrint leaves as parents.
  • If all your Keywords would have a common parent Keyword (so you have a taxonomy), you could use Keyword.GetUsingItems on that parent Keyword.

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.