A simple FetchXml
I did not know until recently that you can actually view your FetchXml through advance find. To do it you have to go to advance find of any record. Once in you need to select a new query. And as soon as you do that you’ll see ‘Download FetchXml’ button in top ribbon.
Now for just to get you guys started let’s do a very simple FetchXml. The following is a sample FetchXml which gets all the contacts in CRM,
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"> <entity name="contact"> <attribute name="fullname" /> <attribute name="telephone1" /> <attribute name="contactid" /> <order attribute="fullname" descending="false" /> </entity> </fetch>
The code itself is very much self explanatory. Entity name is the entity you are selecting. The attribute identifies the columns you are selecting. “Order” notes defines order by statement. The order by is default and not required. Here's almost similar query with 'and' and 'or' condition.
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"> <entity name="contact"> <attribute name="fullname" /> <attribute name="telephone1" /> <attribute name="contactid" /> <order attribute="fullname" descending="false" /> <filter type="and"> <filter type="or"> <filter type="and"> <condition attribute="createdon" operator="on" value="2013-06-26" /> <condition attribute="department" operator="eq" value="IT" /> </filter> <condition attribute="firstname" operator="eq" value="John" /> </filter> </filter> </entity> </fetch>
So there you go, a very simplistic FetchXml from a very novice point of view. For more information you go to MSDN . Also Gareth Tucker’s Blog is ideal place for starters in FetchXml.
No comments:
Post a Comment