Thursday, 9 April 2015

Convert QueryExpression to Fetch XML or FetchXML to QueryExpression

Here is the way to convert to Query Expression to Fetch XML or Fetch XML to Query Expression.

QueryExpression objQueryExpression = new QueryExpression("account");
objQueryExpression.ColumnSet = new ColumnSet("accountid");
// QueryExpression To Fetch XML Conversion.
var queryExpToFetchRequest = new QueryExpressionToFetchXmlRequest
       Query = objQueryExpression
var conversionResponse = (QueryExpressionToFetchXmlResponse)objService.Execute(queryExpToFetchRequest);
string fetchXml = conversionResponse.FetchXml;
string strTestFetchXML = "<fetch distinct='false' no-lock='false' mapping='logical'><entity name='account'><attribute name='accountid' /></entity></fetch>";

// Fetch XML To QueryExpression Conversion.
var fetchToQueryExpressionRequest = new FetchXmlToQueryExpressionRequest
       FetchXml = strTestFetchXML
var fetchToQueryExpressionResponse = (FetchXmlToQueryExpressionResponse)objService.Execute(fetchToQueryExpressionRequest);
QueryExpression objQueryExp = fetchToQueryExpressionResponse.Query;

Happy CRM'img

No comments:

Post a Comment