Export (0) Print
Expand All

ExecuteFetch Message

CRM 1.2
banner art

Executes the specified Fetch XML query.

The relevant classes are specified in the following table.

Type Class
Request ExecuteFetchRequest
Response ExecuteFetchResponse

Remarks

To perform this action, the caller must have the read privilege for the entity type and access rights on the entity instances to be retrieved. For a list of required privileges, see ExecuteFetch Privileges.

This message returns a String type that specifies the XML data containing the results of the query. This XML string is in the following format:

<resultset> + <result>result1</result><result>result2</result> + ... + </resultset> 

The XML string returned from this method may contain multiple entity instances. If no instances are returned the method simply returns an XML document for the entity type, with no data.

The XML string returned from this method does not contain elements for attributes where the value is null or contains empty strings. This improves performance by not sending more XML data than is necessary from the server to the client.

Example

The following code example demonstrates how to use the ExecuteFetch message.

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

// Retrieve all accounts that the user has read access to.
string fetch1 = @"<fetch mapping=""logical"">
                     <entity name=""account"">
                        <all-attributes/>
                     </entity>
                  </fetch>";

// Fetch the results.
ExecuteFetchRequest req = new ExecuteFetchRequest();
req.FetchXml = fetch1;
ExecuteFetchResponse result1 = (ExecuteFetchResponse)service.Execute(req);

// Retrieve all accounts that the user has read access to.
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.
ExecuteFetchRequest req2 = new ExecuteFetchRequest();
req2.FetchXml = fetch2;
ExecuteFetchResponse result2 = (ExecuteFetchResponse)service.Execute(req2);
[Visual Basic .NET]
' Set up the CRM Service.
Dim service As New CrmService()
service.Credentials = System.Net.CredentialCache.DefaultCredentials

' Retrieve all accounts user has read access to.
' Fetch Statement
Dim fetch1 As String = _
        "<fetch mapping='logical'>" + _
           "<entity name='account'>" + _
              "<all-attributes/>" + _
           "</entity>" + _
        "</fetch>"

' Fetch the results.
Dim ExecuteFetchRequest req = New ExecuteFetchRequest()
req.FetchXml = fetch1
Dim ExecuteFetchResponse result1 = (ExecuteFetchResponse)service.Execute(req)

' Retrieve all accounts that the user has read access to.
' Fetch Statement
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 ExecuteFetchRequest req2 = New ExecuteFetchRequest()
req2.FetchXml = fetch2
Dim ExecuteFetchResponse result2 = (ExecuteFetchResponse)service.Execute(req2)

Related Topics

Building Queries

CrmService Messages

Fetch Method

FetchXML Schema


© 2007 Microsoft Corporation. All rights reserved.


Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft