Export (0) Print
Expand All
Expand Minimize

ExecuteFetch Message (CrmService)

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Works for all deployment typesWorks online and offline

Executes the specified Fetch XML query.

The relevant classes are specified in the following table.

TypeClass
RequestExecuteFetchRequest
ResponseExecuteFetchResponse

Remarks

To use this message, pass an instance of the ExecuteFetchRequest class as the request parameter in the Execute method.

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.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0; 
token.OrganizationName = "AdventureWorksCycle";
 
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Retrieve all accounts that the user has read access to.
// Be aware that using all-attributes may adversely affect
// performance and cause unwanted cascading in subsequent 
// updates. A best practice is to retrieve the least amount of 
// data required.
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 owned by the user with the read access rights to the accounts and
// where the last name of the user 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.
ExecuteFetchRequest req2 = new ExecuteFetchRequest();
req2.FetchXml = fetch2;
ExecuteFetchResponse result2 = (ExecuteFetchResponse)service.Execute(req2);
[Visual Basic .NET]
' Set up the CRM Service.
Dim token As New CrmAuthenticationToken()
' You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0
token.OrganizationName = "AdventureWorksCycle";
 
Dim service As New CrmService()
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials

' Retrieve all accounts user has read access to.
' Fetch Statement
' Be aware that using all-attributes may adversely affect
' performance and cause unwanted cascading in subsequent 
' updates. A best practice is to retrieve the least amount of 
' data required.
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 owned by the user with the read access rights to the accounts and
' where the last name of the user is not Cannon.

' 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)

See Also

Concepts

Reference


© 2010 Microsoft Corporation. All rights reserved.


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