5

I have code like this

this.GetContentDeliveryService().Templates.Where(template => template.ItemId 
== presentationItem.Template.ItemNumber).FirstOrDefault();

which fails to find the desired template, even though I know it is in the system, because I can find it at

https://blah.net/WebUI/item.aspx?tcm=32#id=tcm:18-3260-32

The template is not being returned in my result set because OData by default returns only 25 items. I have looked around and it seems like it is possible to get around this by either a) changing the max result size config on the server side, or b) using a URL query syntax with "$top" to control the number of items returned (both explained here). Neither of these options are good, because I can't change the server-side configuration, and I also don't want to query a huge number of items to sift through.

I know exactly the tcm of the template I am interested in - with this information, isn't there a way of querying OData to return a strongly-typed object? I have looked around but have not found such a thing.

Syntax like this looked promising:

http://blah.net/odata.svc/QueryComponentPresentations?$filter=(id eq 'tcm:18-3260-32')

except that I couldn't get it to work in the browser, let alone get it to return a strongly-typed object in code.

Given a template's tcmid, do you know how to query OData for just that item, and get a strongly-typed object in return?

Thanks in advance...

0

1 Answer 1

7

OData is a self-descriptive service, meaning that if you look at http://blah.net/odata.svc/ you will see a list of entities that the service will return:

enter image description here

The collection of entities you're interested in is the last one in the list above, i.e. 'Templates'.

I think this is the query you're looking for:

http://blah.net/odata.svc/Templates(PublicationId=18,ItemId=3260)

You can also construct a query returning the same result in another way:

http://blah.net/odata.svc/Templates?$filter=PublicationId eq '18' and ItemId eq '3260'

BTW, the sample query that you've posted (/QueryComponentPresentations) is from a cool custom OData extension that Mihai built (http://yatb.mitza.net/2013/06/extending-odata-query-functionality.html). It is not out of the box.

Finally, if you haven't yet, take a look at this post explaining the fundamentals of working with Tridion OData.

Happy coding!

8
  • Thanks very much for your response, Nickoli, I appreciate it. Regrettably, it does not work. Using URL's like the above Commented Jul 24, 2013 at 16:44
  • does not work. Using URL's like the above "blah.net/odata.svc/Templates(PublicationId=18,ItemId=3260)" will only return a valid template if the requested template happens to fall within the first batch of returned results (I tested this by finding all the templates returned by "blah.net/odata.svc/Templates", and then requesting one of those, specifically, with the filtering syntax). Commented Jul 24, 2013 at 16:51
  • 1
    I am 100% certain about my query. Something else is not right on your system. Is your template published? Check the database to see if it's in there. Commented Jul 24, 2013 at 17:56
  • 1
    "ListLevels 4" tells me that you're using DD4T. Is this true? Open the template in the CMS and see if it's set to be DYNAMIC. If it's not, then it won't be in your list. Commented Jul 25, 2013 at 16:22
  • 1
    I clicked "Accept this answer" for Nickoli's initial response, because I appreciate very much his helpfulness. Now that I understand the problem more, I believe that my initial question was confused; i.e., I was trying to query for a template that was not Dynamic, and OData doesn't return those. So the behavior I was observing is by design. At the same time, Nickoli's helpful response led me to the correct query syntax for an OData item, as well as the "Execute" method for getting a strongly typed OData object from any URL. I love StackExchange :-) Commented Jul 26, 2013 at 18: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.