Export (0) Print
Expand All
Expand Minimize

QueryExpressionToFetchXml Message (CrmService)

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Works for all deployment typesWorks online and offline

Converts a query represented as a QueryExpression class to the equivalent query represented as Fetch XML.

The relevant classes are specified in the following table.

TypeClass
RequestQueryExpressionToFetchXmlRequest
ResponseQueryExpressionToFetchXmlResponse

Remarks

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

For a list of required privileges, see QueryExpressionToFetchXml Privileges.

Example

The following code example shows how to use the QueryExpressionToFetchXml 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;

// Create the column set.
ColumnSet cols = new ColumnSet();

// Set the properties of the column set.
cols.Attributes = new string [] {"name"};

// Create the ConditionExpression. 
ConditionExpression condition = new ConditionExpression();

// Set the condition for the retrieval to be when the city in the account's address is Sammamish.
condition.AttributeName = "address1_city";
condition.Operator = ConditionOperator.Like;
condition.Values = new string [] {"Sammamish"};

// Create the FilterExpression.
FilterExpression filter = new FilterExpression();

// Set the properties of the FilterExpression.
filter.FilterOperator = LogicalOperator.And;
filter.Conditions = new ConditionExpression[] {condition};

// Create the query.
QueryExpression query = new QueryExpression();

// Set the properties of the query.
query.ColumnSet = cols;
query.Criteria = filter;
query.EntityName = EntityName.account.ToString();

// Create the request object.
QueryExpressionToFetchXmlRequest expression = new QueryExpressionToFetchXmlRequest();

// Set the properties of the request object.
expression.Query = query;

// Execute the request.
QueryExpressionToFetchXmlResponse queried = (QueryExpressionToFetchXmlResponse) service.Execute(expression);
[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

' Create the column set.
Dim cols As New ColumnSet()

' Set the properties of the column set.
cols.Attributes = New String() {"name"}

' Create the ConditionExpression.
Dim condition As New ConditionExpression()

' Set the condition for the retrieval to be when the city in the account's address is Sammamish.
condition.AttributeName = "address1_city"
condition.[Operator] = ConditionOperator.Like
condition.Values = New String() {"Sammamish"}

' Create the FilterExpression.
Dim filter As New FilterExpression()

' Set the properties of the FilterExpression.
filter.FilterOperator = LogicalOperator.And
filter.Conditions = New ConditionExpression() {condition}

' Create the query.
Dim query As New QueryExpression()

' Set the properties of the query.
query.ColumnSet = cols
query.Criteria = filter
query.EntityName = EntityName.account.ToString()

' Create the request object.
Dim expression As New QueryExpressionToFetchXmlRequest()

' Set the properties of the request object.
expression.Query = query

' Execute the request.
Dim queried As QueryExpressionToFetchXmlResponse = CType(service.Execute(expression), QueryExpressionToFetchXmlResponse)

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