[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
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.
1: //# [CrmService.Fetch Method]
2: // Set up the CRM Service.
3: CrmAuthenticationToken token = new CrmAuthenticationToken();
4: // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory Authentication.
5: token.AuthenticationType = 0;
6: token.OrganizationName = "AdventureWorksCycle";
7:
8: CrmService service = new CrmService();
9: service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
10: service.CrmAuthenticationTokenValue = token;
11: service.Credentials = System.Net.CredentialCache.DefaultCredentials;
12:
13: // Retrieve all attributes for all accounts.
14: // Be aware that using all-attributes may adversely affect
15: // performance and cause unwanted cascading in subsequent
16: // updates. A best practice is to retrieve the least amount of
17: // data required.
18: string fetch1 = @" <fetch mapping=""logical"">
19: <entity name=""account"">
20: <all-attributes/>
21: </entity>
22: </fetch>";
23:
24: // Fetch the results.
25: String result1 = service.Fetch(fetch1);
26:
27: // Retrieve the name and account ID for all accounts where
28: // the account owner's last name is not Cannon.
29: string fetch2 = @"<fetch mapping=""logical"">
30: <entity name=""account"">
31: <attribute name=""accountid""/>
32: <attribute name=""name""/>
33: <link-entity name=""systemuser"" to=""owninguser"">
34: <filter type=""and"">
35: <condition attribute=""lastname"" operator=""ne"" value=""Cannon""/>
36: </filter>
37: </link-entity>
38: </entity>
39: </fetch>";
40:
41: // Fetch the results.
42: String result2 = service.Fetch(fetch2);