9

I would like to use OData service to get component presentations based on conditions, but I am running into some problems. I am aware that Tridion OData service is "limited" OData, so I was wondering is something like this possible through Tridion OData (in a single query):

Get all component presentations where CT has id 40 and Component contains keyword A and keyword B.

I have tried filtering on custom metas and expanding on Component/ComponentPresentations but this is not returning only items that I need I can not filter further on the expanded set...

Is this possible with OData or should I "play it safe" and just use broker api ?

Adding additional information:

Slightly simplifying scenario to better explain what I am trying to do:

Get all CP's from publication 1 based on custom meta

...odata.svc/CustomMetas?$filter=KeyName eq 'Rank' and StringValue eq 'A' and PublicationId eq 1 &$expand=Component/ComponentPresentations

Get all CP's based on CT ID

...odata.svc/ComponentPresentations?$filter=PublicationId eq 1 and TemplateId eq 40&$expand=Component/CustomMetas

How do I combine these two conditions and get all CP's which are rendered with CT 40 and have keyword Rank with value A in just a single call to odata ?

  • Interesting question. Perhaps it would be clearer if you added some examples of the queries you've tried. – Dominic Cronin Nov 14 '14 at 8:34
  • @DominicCronin additional info added – user3760419 Dec 8 '14 at 13:21
7
+100

Considering you want the component presentations your main query should be for that and then filter on the presence of specific custom metas like

odata.svc/ComponentPresentations?$filter=(TemplateId eq 40) and (PublicationId eq 1) and (Component/CustomMetas/any(m: m/KeyName eq 'Rank' and m/StringValue eq 'A'))&$expand=Component/CustomMetas

which should work but it doesn't as the "any" quantifier isn't supported by the CD webservice's implementation of OData.

Making the filter query directly on an expanded property also doesn't appear to be supported (and would technically be wrong according to the OData specification as CustomMetas is a collection and not a single property):

odata.svc/ComponentPresentations?$filter=(TemplateId eq 40) and (PublicationId eq 1) and (Component/CustomMetas/KeyName eq 'Rank' and Component/CustomMetas/StringValue eq 'A')&$expand=Component/CustomMetas

Note that even just filtering on component title doesn't work:

odata.svc/ComponentPresentations?$filter=(PublicationId eq 1) and (Component/Title eq 'Test')&$expand=Component/CustomMetas

Without this last (very basic) support for filtering on expanded properties I believe there is no solution to your problem.

If there are few DCPs matching these criteria you might get away with

odata.svc/CustomMetas?$filter=KeyName eq 'Rank' and StringValue eq 'A' and PublicationId eq 1 &$expand=Component/ComponentPresentations

and using an XPath filter to filter out component presentations with the correct CT ID from the result; that would still limit the number of calls to the OData webservice to 1 even if you are retrieving more data then you need...

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.