Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

CrmService.Fetch Method

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

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

Syntax

[Visual Basic .NET]
Public Function Fetch(
  ByVal fetchXml As String
) As String
[C#]
public string Fetch(
  string  fetchXml
);

Parameters

fetchXml

Specifies a String that contains the fetch query string to be executed.

Return Value

Returns an XML String type 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.
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 attributes for all accounts.
// 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.
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 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 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.
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)

Requirements

Namespace: CrmService

See Also

Concepts

Tasks

Reference


© 2010 Microsoft Corporation. All rights reserved.


Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.