We would like to build a query to list the contacts who lives in London. So we navigated to Adavanced Find option, which is one of the best features of MS Dynamcis CRM.
Once you click on the Download Fetch XML option, you could save the XML file to your local machine. The XML file contents is purely based on the query that the user made. For instance our query was based on the city field.
Another example could be if you want to retrieve all account records then the XML file contents would be
<fetch mapping='logical'>
<entity name='account'><all-attributes/></entity>
</fetch> |
FetchXmlToQueryExpressionRequest req = new FetchXmlToQueryExpressionRequest();
req.FetchXml = "<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"><condition attribute="address1_city" operator="eq" value="London" /></filter></entity></fetch>";
FetchXmlToQueryExpressionResponse resp = (FetchXmlToQueryExpressionResponse)service.Execute(req);
So the resp variable will have the results as per the query ( In this case query in the form of fetch XML)
OR
string fetchXML="<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"><condition attribute="address1_city" operator="eq" value="London" /></filter></entity></fetch>";
EntityCollection resp = service.RetrieveMultiple(new FetchExpression(fetchXML));
No comments:
Post a Comment