4

I'm trying to get all the components based on a Schema and from a particular Publication using the Tridion coreservice 2011.

I am using the code below but it gives only the Components that are created in that particular Publication. However, I need shared Components that are visible (from the parent publication) as well

var filter = new UsingItemsFilterData { ItemTypes = new[] { ItemType.Component }};
filter.InRepository = new LinkToRepositoryData();
filter.InRepository.IdRef = "tcm:0-pubId-0";
var componentListElement = client.GetListXml("SchemaId", filter);

2 Answers 2

5

Check this sample code using a SearchQueryData.

SearchQueryData query = new SearchQueryData() {
    BasedOnSchemas = new BasedOnSchemaData[] { 
        new BasedOnSchemaData(){ 
            Schema = new LinkToSchemaData(){ IdRef= "{schemaId}" }
        }
    },
    SearchIn = new LinkToIdentifiableObjectData() { IdRef = "{publicationId}" }, 
    ItemTypes = new ItemType[]{ ItemType.Component }
};

XElement xResults = channel.GetSearchResultsXml(query);

for more information about Search Queries and the Core Services check this post: Search Queries

1
  • This fits and solves my requirement :) Thank you very much Huiza Jul 29, 2013 at 21:20
4

The reason why you are getting only the items created or localized in the Publication you specified is because you are basically requesting the following from the system:

  • Get me a list of items related to my specified subject as XML
  • Constrain results to Components
  • Constrain results to specified Publication

What you see is that the shared items are not really available in that Publication. Plus the fact that the Where Used data is not designed to list you contents like shown in a Folder.

To list them via a UsingItemsFilter, you would have to drop the InRepository property and then in the results:

  1. filter out duplicate item IDs
  2. filter out items from child Publications
  3. replace the Publication IDs of parent Publications in your context Publication

Number 1 and 3 are relatively easy to do with an XSLT, but for number 2 you would need to have information about the entire BluePrint chain, which is not as easy to get.

The only two other options you have available of getting such a list, is getting a list of all Components in that Publication and filtering that by Schema (which requires multiple calls since the initial list will not give you Schema info), or using a Search query as answered by Eric already.

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.