Answered by:
FetchXML filter

Question
-
I am trying to build a filter in a FetchXML statement to do the following (using T-SQL syntax):
where (gradefilter = 0) or (minimumgrade >= 1 and maximumgrade <=12)
would this filter statement do that?
<filter type='or'>
<condition attribute='gradefilter' operator='eq' value='0'/>
</filter>
<filter type='and'>
<condition attribute='minimumgrade' operator='le' value='1'/>
<condition attribute='maximumgrade' operator='ge' value='12'/>
</filter>
I used Stunware's FetchXMLBuilder to do that, but I'm not sure it's what I'm looking for.
Thanks
Ben
Tuesday, February 8, 2011 6:27 PM
Answers
-
Hi Ben
The first </filter> should be at the very end, and "ge" and "le" should switch places.
This should do it:
<filter type='or'> <condition attribute='gradefilter' operator='eq' value='0'/> <filter type='and'> <condition attribute='minimumgrade' operator='ge' value='1'/> <condition attribute='maximumgrade' operator='le' value='12'/> </filter> </filter>
/Jonas
- Proposed as answer by Daniel Cai - KingswaySoftMVP Tuesday, February 8, 2011 6:59 PM
- Marked as answer by MrKrabs Tuesday, February 8, 2011 8:25 PM
Tuesday, February 8, 2011 6:52 PM
All replies
-
Hi Ben
The first </filter> should be at the very end, and "ge" and "le" should switch places.
This should do it:
<filter type='or'> <condition attribute='gradefilter' operator='eq' value='0'/> <filter type='and'> <condition attribute='minimumgrade' operator='ge' value='1'/> <condition attribute='maximumgrade' operator='le' value='12'/> </filter> </filter>
/Jonas
- Proposed as answer by Daniel Cai - KingswaySoftMVP Tuesday, February 8, 2011 6:59 PM
- Marked as answer by MrKrabs Tuesday, February 8, 2011 8:25 PM
Tuesday, February 8, 2011 6:52 PM -
I think you have got everything right. Using stunnware tools is a smart choice, which could really save you a lot of time.
Daniel Cai | http://danielcai.blogspot.comTuesday, February 8, 2011 6:52 PM -
Using Advanced Find:-
<filter type="and"> <filter type="and"> <condition attribute="numberofemployees" operator="eq" value="0"/> <filter type="or"> <condition attribute="numberofemployees" operator="lt" value="10"/> <condition attribute="numberofemployees" operator="gt" value="1"/> </filter> </filter> </filter>
Regards FaisalTuesday, February 8, 2011 6:58 PM -
Hmm, I didn't spot that problem. Jonas has got you a right answer. I was only looking at the combinations...
Daniel Cai | http://danielcai.blogspot.comTuesday, February 8, 2011 7:00 PM -
Good catch Jonas. I was a little trigger happy when I made my selection in the dropdown.
Here is what I have now. I'm trying to filter the program lookup based on the filter I'm asking about. When I select the lookup I get a generic "An error has occured". Any idea what I'm doing wrong? This FetchXML works in the builder tool.
//filter the program lookup
var field = crmForm.all.new_programid;
// Ensure that search box is not visible in a lookup dialog
field.lookupbrowse = 1;
var SearchString;SearchString = "<fetch mapping='logical'><entity name='new_program>"
+ "<filter type='or'>"
+ "<condition attribute='new_gradefilter' operator='eq' value='0'/>"
+ "<filter type='and'>"
+ "<condition attribute='new_minimumgrade' operator='ge' value='1'/>"
+ "<condition attribute='new_maximumgrade' operator='le' value='12'/>"
+ "</filter></filter>"
+ "</entity></fetch>";
field.AddParam("search",SearchString);Thanks
Ben
Tuesday, February 8, 2011 7:36 PM -
Did you apply the server hack necessary to use the Lookup filtering this way? Instructions here: http://crm.georged.id.au/post/2008/02/16/Filtering-lookup-data-in-CRM-4.aspx If you've already made the appropriate, unsupported modifications, be sure to restart IIS. There are several other good options to filtering lookups that you might look into, as well.
Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.Tuesday, February 8, 2011 7:57 PMModerator -
Yes I've applied the hack. I'm using filtered lookups like this in other places without any issue. What's the best way to find out the actual error message?Tuesday, February 8, 2011 8:06 PM
-
Just found the problem I had:
<entity name='new_program>"
when I needed
<entity name='new_program'>"
Thanks for the help everyone!Tuesday, February 8, 2011 8:25 PM