Convert fetchXML to SQL Query in MSCRM 4.0

If for some sane reasons if fetchxml needs to be converted to a SQL Query in MSCRM 4.0, it is possible.

It actually requires the below DLL's which are avilable in the folder Server\setup
Microsoft.Crm.dll, Microsoft.Crm.Platform.Server.dll and Microsoft.Crm.Reporting.dll

The code looks as below :


Microsoft.Crm.BusinessEntities.ExecutionContext myContext = new Microsoft.Crm.BusinessEntities. ExecutionContext (OrganizationId from the context);
myContext.OnBeginRequest(UserId, false);

Microsoft.Crm.Reporting.ReportQueryBuilder myreportQueryBuilderObj = new ReportQueryBuilder();
string Query = myreportQueryBuilderObj.BuildReportQuery(fetchXml, myContext);

The query will be returned as string. The Query is not readable but it works, -:)

Comments

  1. And how can i create execution context?
    Can you provide full code?
    Thanks in advance!

    ReplyDelete
  2. I try it, but i got an exception. do you have the full code.
    Thanks in advance

    ReplyDelete
  3. Hi ,

    I made this tool might it help you.

    mail me if you need this.. it free !!

    sbhagat@yamaha-motor-india.com

    ReplyDelete
  4. Hi!
    When i use in link-entity condition lookup BuildReportQuery return null. Any ides?

    ReplyDelete

Post a Comment

Popular posts from this blog

The famous Vanilla story --

DOGL - Day ONE GO LIVE