3

I would like to get all Pages using a Component that are in the current Publication, as shared from a Parent or a local Page.

Component and Page are in Blueprint Parent. Page is sometimes localized on other Publications (not this one, and do not want those). I want to get the Pages within this Publication and the Parent, but not other siblings.
However, my code gets all Pages in the system using the Component, the same results as the Tridion 'WhereUsed' functionality does in the GUI. (Which is correct behavior, I guess).

Below my code that gets all Pages everywhere.

Maybe I'll have to write some extra code that gets the Blueprint parents of my current Publication and if the Page is found there then add it to my results, but I hope not.

UsingItemsFilterData usingItemsFilterData = new UsingItemsFilterData
{
    BaseColumns = ListBaseColumns.Default, // to specify the detail in the XML
    ItemTypes = new[] { ItemType.Page, ItemType.Component} ,
    IncludeLocalCopies = true                
};

XElement usingXML = client.GetListXml(compUri, usingItemsFilterData);
5

To get the results from a particular repository, UsingItemsFilterData object has a property InRepository.

UsingItemsFilterData usingItemsFilterData = new UsingItemsFilterData
            {
                BaseColumns = ListBaseColumns.Default, // to specify the detail in the XML
                InRepository = new LinkToRepositoryData(){IdRef="tcm:x-y-z"},
                ItemTypes = new[] { ItemType.Page, ItemType.Component },
                IncludeLocalCopies = true
            };

after setting the proper value, the results will be constrained by the specified InRepository value in the filter. So, if the value is set to a TcmUri of a Repository, only items in that Repository will be included in the results.

As Mentioned in comments by @David Forster, if the property "InRepository" excludes the shared items from parent. you have two options:

  1. fire the client.GetListXml twice for parent and local publication and join the results.

  2. Don't use the "InRepository" property and filter the resulting xml for the parent and local publication.

  • 3
    using "InRepository" will then exclude shared pages which contain the component. Robert requires these I think. – David Forster Mar 26 '15 at 15:01
  • Thanks for the answer. But, how can I get the Parent publication? For me it could be from a global English level or a translation level. – robrtc Mar 26 '15 at 15:45
  • you can use the "Parents" property of publicationdata object var pubData = (PublicationData)client.Read("tcm:0-x-1", new ReadOptions()); pubData.Parents – Saurabh Gangwar Mar 26 '15 at 16:17
  • 1
    I'm thinking to do a unique filter (linq) on the item ID to get a smaller list, and then for each item in the list make a new URI, using the WhereUsed ID and the Component's Publication ID, and then do a Core Service read with the new URI to see if it exists, and I could then assume it is a shared item. :) A long way to go to get it, but I guess it will work – robrtc Mar 26 '15 at 17:02
  • 1
    About the previous suggestions, I guess the best explanation is 'you can't get there from here...' and there is no simple or clean way to get this information using the all-powerful GetListUsingItems... – robrtc Mar 26 '15 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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