CrmService.Fetch Method

banner art

Retrieves entity instances in XML format based on the specified query expressed in the FetchXML query language.

Syntax

[Visual Basic]
Public Function Fetch(
  ByVal fetchXml As String
) As String

[C#]
public string Fetch(
  string  fetchXml
);

[JScript]
public function Fetch(
  fetchXml : String
) : String;

Parameters

fetchXml

A string that contains the fetch query string to be executed.

Return Value

Returns a String type that is an XML string that contains the results of the query.

Remarks

Use this method to execute a query expressed in the FetchXML query language.

To perform this action, the caller must have the Read privilege to the entity types being retrieved and access rights on the entity instances retrieved.

Example

The following example demonstrates the use of the Fetch method.

[C#]
// Set up the CRM service.
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

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

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

// Retrieve the name and account ID for all accounts where
// the account owner's 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 that the user has read access to.
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 that the user has read access to.
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)

See Also

© 2007 Microsoft Corporation. All rights reserved.