The New Tridion 2011 Criteria Objects

Despite minor confusion on how the new Tridion 2011 Criteria objects work, the dev teams I work with are satisfied with the new criteria objects (or maybe just relieved that the recent upgrade is nearly done).

I kind of miss that insider-knowledge that a custom Tridion broker metadata query involved multiple key/value "ANDs" separated by "ORs" and combined with a "GROUP BY"! However, the new objects will be easier to explain and maintain.

After your Tridion content management explorer (CME) site is all set up (VM or otherwise) and you're able to publish to a presentation server, you can use the new Criteria objects to pull back matching custom metadata fields and/or values from the broker database.

For example, to find components that have the key name "city," use the following in your presentation server code-behind (C#):

CustomMetaKeyCriteria keyCity = new CustomMetaKeyCriteria("city");

To find specific values, use:

CustomMetaValueCriteria valueLocal = new CustomMetaValueCriteria("San Diego");

You could combine these with an "AND" criteria matches as in:

AndCriteria andCriteria = new AndCriteria(keyCity, orCriteria);

However, to really get a query or filter that matches a key name (the stored XML field name in the content management explorer) to its saved value, you probably want:

CustomMetaValueCriteria value = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("city"), "San Diego");

Using "ANDs" instead of the two-paramater CustomMetaValueCriteria object could work most of the time until you run into a scenario with a match on the key in one (broker database) column and a separate match in the value column for the same component. Tridion 2011 stores the key/value pairs as separate rows in the database making for cleaner queries, but be sure to use the correct Criteria objects. Just cause a filter pulls back Tridion content management identifiers (tcmids) it doesn't mean the query logic is right.

Big thanks to the ASH team and Tridion's Nuno for the help with these on TridionWorld and with Tridion Professional Services (thanks to Tory Johnson)/support/R&D for pointing out the distinction. Nothing like a little collaborations to find a seemingly simple fix.

I highly recommend working with support for your critical issues, joining the forum for a broad range of perspectives from an active partner and developer community, and if you're fairly Tridion-savvy... jump in on the #tridion #oneliner meme going around on Twitter while it lasts.

4 comments :

  1. i need to fetch value from broker db on basis of some value in column...
    Eg: i have a column called 'Breaking ALert'in the schema.. and i need to fetch those component which have 'Breaking ALert' set to yes..

    how could i do that?

    ReplyDelete
  2. You'll need to make sure the breaking alert is in the metadata tab of the schema. From there, you'll apply the same as above against a Query object:

    CustomMetaValueCriteria value = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("Breaking Alert"), "Yes");

    Be careful with these boolean yes/no type filters and metadata. Consider grouping up similar "features" using a category and keywords so that you can then filter for groups of options instead of one-at-a-time.

    Be sure to also visit http://www.tridionworld.com/ to get help from, and share with, the bigger community.

    ReplyDelete
  3. I have to create TaxonomyKeywordCriteria in which number of keywords is not fix,they can vary.Suggest me how to use TaxonomyKeywordCriteria[].

    ReplyDelete
  4. See SDL Live Content for a TaxonomyKeywordCriteria example. However since the IDs are difficult to predict without knowing them (you'd have to publish), consider using TaxonomyKeywordNameCriteria instead.

    ReplyDelete

Feel free to share your thoughts below.

Some HTML allowed including links such as: <a href="link">link text</a>.