Answered by:
Need help with oData "$select/$filter" statement

Question
-
Hello All,
I am using oData to get some information related to some entities. But I am having trouble creating a compound $filter statement.
I want to find all records "CheckRegister" records that belong to the current Contact where the "Amount" is greater than 5.
Here is a snippet that I am trying to use. but when I make the call, my result set is null.
Where am I going wrong?
var memberId = Xrm.Page.data.entity.getId().replace("{","").replace("}",""); var filter = "?$select=new_registerId,new_registerdate, new_registeramount" +"&$filter=new_OwningContactId/Id eq (guid'" + memberId + "')" +" and new_registeramount ge 5"; // <-- problem clause var entries = retrieveRecord("new_registerSet", filter); // retrieveRecord is a function that gets all matching records. // It is working and isn't a problem here.
if I leave out the "and new_registeramount ge 5" part, everything works well. While testing/troubleshooting, I find that I have the same problem with other entities, so I suspect that it is a problem with my syntax.
Any suggestions on where I'm going wrong?
TIA,
-tomas
Thursday, March 8, 2012 2:06 AM
Answers
-
What Data Type is 'new_registeramount'? If, for instance, it is a Currency or Picklist type, you'll need to access the Value property, thus:
$filter=new_OwningContactId/Id eq (guid'" + memberId + "') and new_registeramount/Value ge 5
--pogo (pat) @ pogo69.wordpress.com
- Marked as answer by DadKind Thursday, March 8, 2012 6:47 PM
Thursday, March 8, 2012 4:09 AM
All replies
-
Try putting the brackets as shown in the example below
$filter=(Address1_Country ne null) and (Address1_City ne null)
Also test it in browser
http://www.mscrmshop.blogspot.com.au/2011/06/using-rest-endpoints-in-crm-2011rest.html
I hope this helps.
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com
- Proposed as answer by Amreek Singh Thursday, March 8, 2012 2:20 AM
Thursday, March 8, 2012 2:20 AM -
The CRM 2011 OData Query Designer is a great tool for building queries: http://crm2011odatatool.codeplex.com/Thursday, March 8, 2012 3:33 AM
-
What Data Type is 'new_registeramount'? If, for instance, it is a Currency or Picklist type, you'll need to access the Value property, thus:
$filter=new_OwningContactId/Id eq (guid'" + memberId + "') and new_registeramount/Value ge 5
--pogo (pat) @ pogo69.wordpress.com
- Marked as answer by DadKind Thursday, March 8, 2012 6:47 PM
Thursday, March 8, 2012 4:09 AM -
Yeah pogo is right.
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com
Thursday, March 8, 2012 4:23 AM -
Thanks for the quick response!!
For which Types would I need to specify the "Value"?
You mention Currency and Picklist. Are there others? Is there an MSDN article which would detail this?
-tomas
Thursday, March 8, 2012 6:16 AM -
http://msdn.microsoft.com/en-us/library/gg334767.aspx
http://msdn.microsoft.com/en-us/library/gg309461.aspx#BKMK_filter
I hope this helps.
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com
Thursday, March 8, 2012 10:52 AM -
Thanks for the "test in browser". This was very instrumental in helping me solve my problems.Thursday, March 8, 2012 6:48 PM