How to get all Components based on a Schema and from a particular Publication?
-
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);
-
Answer:
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: http://erichuiza.blogspot.com/2012/06/performing-search-queries-with-core.html
user1357019 at Tridion Visit the source
Other answers
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: filter out duplicate item IDs filter out items from child Publications 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 http://tridion.stackexchange.com/questions/2320/how-to-get-all-components-based-on-a-schema-and-from-a-particular-publication/2322#2322 as answered by Eric already.
Bart Koopman
Related Q & A:
- How to rotate a Direction Arrow to a particular location?Best solution by Stack Overflow
- How to get the source file of a particular type?Best solution by social.msdn.microsoft.com
- How to get a summer job on a cruise ship?Best solution by Yahoo! Answers
- How to get a Camera Signal to a TV?Best solution by answers.yahoo.com
- How to get a PR?what are the conditions to get a PR?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.