Darren Liu's Blog

Retrieve Records filtering on an Entity Reference field using OData

leave a comment »

I ran into a problem today trying to retrieve records filtering on an Entity Reference field using the OData endpoint.  Thanks to Jim Daly for helping me. An Entity Reference field contains several properties and Id is one of the its properties.  Usually when you are filtering using OData, all you have to do is use the keyword $filter, the search field, operator and the value.

For example, to retrieve all the accounts where address1_city equal Redmond, you’ll do the following:

/AccountSet?$filter=Address1_City eq 'Redmond' 
 
However to retrieve from an Entity Reference field is little bit different.  To access the properties in an Entity Reference field, you just need to use the forward slash “/” and then follow by the property name.
 
For example, to retrieve all the accounts where primarycontactid equal to {guid}, you have to do the following:
 
AccountSet?$filter=PrimaryContactId/Id eq (Guid'567DAA8F-BE0E-E011-B7C7-000C2967EE46') 

I hope this help in your next project.
Advertisements

Written by darrenliu

01/28/2011 at 1:00 am

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: