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 XML To QueryExpression Conversion.
var fetchToQueryExpressionRequest = new FetchXmlToQueryExpressionRequest
       FetchXml = strTestFetchXML
var fetchToQueryExpressionResponse = (FetchXmlToQueryExpressionResponse)objService.Execute(fetchToQueryExpressionRequest);
QueryExpression objQueryExp = fetchToQueryExpressionResponse.Query;

Happy CRM’img

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s