1 out of 3 rated this helpful - Rate this topic

Using FetchXML

CRM 1.2
banner art

Fetch is a proprietary query language used in Microsoft CRM. It is based on a schema that describes the capabilities of the language. It is used with the Fetch method. See FetchXML Schema.

Examples

The first FetchXML statement retrieves all accounts. The second retrieves all accounts where the last name is not equal to Cannon. Note that in either case, the privileges of the logged on user will affect the set of records returned. The Fetch method only retrieves records for which the logged on user has read access.

// Set up the CRM Service.
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Retrieve all accounts.
string fetch1 = "<fetch mapping='logical'>";
fetch1 += "<entity name='account'><all-attributes/>";
fetch1 += "</entity></fetch>";

// Fetch the results.
String result1 = service.Fetch(fetch1);

// Retrieve all accounts where the last name is not Cannon.
string fetch2 = @"
   <fetch mapping='logical'>
      <entity name='account'>
<attribute name='accountid'/>
<attribute name='name'/>
<link-entity name='systemuser' to='owninguser'>
   <filter type='and'>
      <condition attribute='lastname' operator='ne' value='Cannon' />
   </filter>
</link-entity>
      </entity>
   </fetch>
   ";

// Fetch the results.
String result2 = service.Fetch(fetch2);
[Visual Basic .NET]
' Set up the CRM Service.
Dim service As New CrmService()
service.Credentials = System.Net.CredentialCache.DefaultCredentials

' Retrieve all accounts.
Dim fetch1 As String = _
      "<fetch mapping='logical'>" + _
"<entity name='account'>" + _
   "<all-attributes/>" + _
"</entity>" + _
      "</fetch>"

' Fetch the results.
Dim result1 As String = service.Fetch(fetch1)

' Retrieve all accounts where the last name is not Cannon.
Dim fetch2 As String = _
      "<fetch mapping='logical'>" + _
"<entity name='account'>" + _
   "<attribute name='accountid'/>" + _
   "<attribute name='name'/>" + _
   "<link-entity name='systemuser' to='owninguser'>" + _
      "<filter type='and'>" + _
"<condition attribute='lastname' operator='ne' value='Cannon' />" + _
      "</filter>" + _
   "</link-entity>" + _
"</entity>" + _
      "</fetch>"

' Fetch the results.
Dim result2 As String = service.Fetch(fetch2)

© 2007 Microsoft Corporation. All rights reserved.


Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.