7

I have a simple SDL Tridion 2011 SP1 Broker Query to retrieve a list of Component URIs. All of my Components are embedded on Pages, and not using Dynamic Component Templates. The following code returns 50 results (which is to be expected). One of which is the URI tcm:123-456-16.

List<Criteria> criteria = new List<Criteria>();
criteria.Add(new ItemTypeCriteria(16));
criteria.Add(new PublicationCriteria(337));
Query query = new Query(CriteriaFactory.And(criteria.ToArray<Criteria>()));
String[] results =  query.ExecuteQuery();

The Component tcm:123-456-16 is based on a Schema with the name “News Portal”. I would like to add additional criteria to my query so that I only get items based on that Schema, so I tried the following code:

List<Criteria> criteria = new List<Criteria>();
criteria.Add(new ItemTypeCriteria(16));
criteria.Add(new PublicationCriteria(337));
criteria.Add(new SchemaTitleCriteria("News Portal"));
Query query = new Query(CriteriaFactory.And(criteria.ToArray<Criteria>()));
String[] results =  query.ExecuteQuery();

This returns no results at all. I have double checked my Schema name. Is this response expected? Does the SchemaTitleCriteria require the Components to be published as Dynamic Component Presentations. Any advice would be greatly appreciated.

3
  • Does it work when you change the criteria to new SchemaTitleCriteria("News Portal", Criteria.Like)? Commented Mar 8, 2013 at 10:57
  • Does it work if you use ItemSchemaCriteria(int schemaId)? (I know that you probably don't want to use this because of the need to hardcode/configure the schemaIs, but it may help with the investigation) Commented Mar 8, 2013 at 14:23
  • Schema ID works fine - Like doesn't work. It seems the Schema title field is only populated once you have published DCPs based on it. Commented Mar 8, 2013 at 14:34

1 Answer 1

4

It turns out that you must publish at least one DCP using a component based on the schema in question (in this case News Portal) . Only then will the schema title get added to the Broker DB, at which point SchemaTitleCriteria works fine.

2
  • 1
    This strikes me as a bug in the product (or at least a shortcoming in the API documentation) as it is inconsistent with the ItemSchemaCriteria(int schemaId) behaviour. Commented Mar 8, 2013 at 14:50
  • I tend to agree Commented Mar 8, 2013 at 17:05

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.