web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Calling Crystal Report from AX 2012 R2

(0) ShareShare
ReportReport
Posted on by 3,089

Dear Experts,

Does anyone has try to open/call Crystal Reports from AX 2012 R2 or AX 2012. If yes kindly please help me in this regard.

Best Regards,

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    235,876 Most Valuable Professional on at
    RE: Calling Crystal Report from AX 2012 R2

    mnaeembaigAX, please stop duplicating your question - you already have a thread for it (Crystal reports ActiveX - change DSN properties from code).

    You probably overlooked my reply there, otherwise you would have already known how to paste source code to this forum.

  • mnaeembaigAX Profile Picture
    80 on at
    RE: Calling Crystal Report from AX 2012 R2

    I am having the following error;

    Method 'add' in COM object of class 'INameValuePairs' returned error code 0x80070057 (E_INVALIDARG) which means: One or more arguments are invalid.

    This error is being generated on the following line of code;

    IConnectionProperty = INameValuePairs.add("Use DSN Default Properties",False);

    I want to change the value of “Use DSN Default Properties” at runtime.

    We have a TMS application, the reports of which we want to display in AX. These reports successfully run on TMS when “Use DSN Default Properties” is set to True. On setting it to False the reports do not work in TMS.

    3554.cr.png

    But with “Use DSN Default Properties=True” these reports are not working in AX. Following error is generated in AX.

    Method 'readrecords' in COM object of class 'IReport' returned error code 0x80047E48 (<unknown>) which means: Logon failed.

    Details: [Database Vendor Code: 18456 ].

    This error is being generated on the following line of code;

    reporting.readrecords();

    When I change this value to False at report level, no error is then generated in AX at reporting.readrecords(); line. But again, they stopped working in TMS when its value is changed to False.

    Hence, I want to change its value at runtime for running them in AX. How can I change the value of "Use DSN Default Properties" to False at runtime, any help will be appreciated.

    Following is the complete code;

    public void run()

    {

    Com comapp;

    Com reporting;

    Com IDatabase;

    Com IDatabaseTable;

    Com IDatabaseSingleTable;

    Com INameValuePairs;

    Com INameValuePairs2;

    Com INameValuePairs3;

    COM tc;

    COM IConnectionProperty2;

    Com IConnectionProperty;

    Com ds;

    COM DLL_Name;

    str paramwhole;

    str paramfilename;

    str paramCond;

    str ViewYesNo;

    int ret;

    str selectionFormula;

    COMVariant variant;

    DialogButton diagBut;

    str strMessage;

    str strTitle;

    ;

    super();

    variant = new COMvariant(COMVariantInOut::OUT,COMVariantType::VT_BOOL) ;

    //paramwhole = this.args().parm("'{Employee.empcode}'='11752'");

    paramwhole = this.args().parm();

    //paramwhole = this.args().parm("{Employee.empcode}='11752'");

    //paramwhole = this.args().parm("{?DateFrom}='01/01/2021';{?DateTo}='03/03/2021';{Employee.empcode}='11752'");

    comapp = new COM("CrystalRuntime.Application.11");

    ret = strfind(paramwhole,"|",2,strlen(paramwhole));

    paramfilename = "e:\\Report10.rpt"; //substr(paramwhole,2,ret-2) ;

    ViewYesNo = substr(paramwhole,1,1);

    reporting = comapp.openreport(paramfilename);

    reporting.discardsaveddata();

    comapp.LogonServer("crdb_odbc.dll","tms","tacs", "sa", "Hubleather123");

    // breakpoint;

    IDatabase =reporting.Database();

    IDatabaseTable = IDatabase.Tables();

    IDatabaseSingleTable = IDatabaseTable.Item(1);

    INameValuePairs = IDatabaseSingleTable.connectionproperties();

    IConnectionProperty = INameValuePairs.add("Use DSN Default Properties",False);

    paramcond = substr(paramwhole,ret+1,strlen(paramwhole));

    reporting.RecordSelectionFormula(paramCond);

    reporting.readrecords();

    if(ViewYesNo == 'N')

    {

    variant.boolean(false);

    reporting.PrintOut(variant);

    }

    else

    {

    ActiveX.ReportSource(reporting);

    ActiveX.width(600);

    ActiveX.height(350);

    ActiveX.DisplayToolbar(true);

    ActiveX.DisplayGroupTree(false);

    ActiveX.ViewReport();

    ActiveX.Refresh();

    }

    }

  • Mehul Thacker Profile Picture
    165 on at
    RE: Calling Crystal Report from AX 2012 R2

    Hi Ahmed,

    How did you get windows form & CrsytalReportViewer in AX?

    I think ReportDocument is not AX class, how did you get that using any dll?

    Regards,

    Mehul Thacker

  • Verified answer
    Ahmed Muhammad Alam Profile Picture
    3,089 on at
    RE: Calling Crystal Report from AX 2012 R2

    Dear Experts,

    The problem has been solved. I have a win form and drag a CrsytalReportViewer. On the load of the form I have written the following code.

    ReportDocument rd = new ReportDocument();            rd.Load(System.Web.HttpContext.Current.Server.MapPath("ItemDetail.rpt"));

    crystalReportViewer1.ReportSource = rd;

    crystalReportViewer1.RefreshReport();

    and within the class just call the form to display.

  • Ahmed Muhammad Alam Profile Picture
    3,089 on at
    RE: Calling Crystal Report from AX 2012 R2

    Dear Experts,

    I have tried to call the Crystal Report from AX 2012 R2. I have written a code in VS 2012 C# project and added to the AOT. The calling functionality from AX 2012 X++ is perfectly fine, but the Crystal Report is not opening. Following code written in C# project. Can anyone help me in this regards i.e. why the report is not opening.

    public void CallCrystalReport()

    {

               CrystalReportViewer crv = new CrystalReportViewer();

               string reportPath = @"D:\Reports\SERVICE_INVOICE.rpt";

               ReportDocument rd = new ReportDocument();

               rd.Load(reportPath);

               crv.ReportSource = rd;

               crv.RefreshReport();

    }

  • Brandon Ahmad Profile Picture
    2,465 User Group Leader on at
    RE: Calling Crystal Report from AX 2012 R2

    Not doing reports within the framework is nearly always a mistake.  You have to provide your own execution context which really messes things up and adds a lot of complexity.  

    That being said to answer your question, here is a link:  

    erptechnician.net/.../open-web-page-from-menu-item-in-dynamics-ax

    Essentially, using the web menu item gives you a url option if your client is using a hosted crystal report or any other report (you just need a url).  But warn the company.  There is a whole other can of worms that they will encounter if trying to use Crystal Reports to replace AX SSRS functionality.  

  • Community Member Profile Picture
    on at
    RE: Calling Crystal Report from AX 2012 R2

    Not so much idea on crystal but probably you can use the HTML Browser control to open your crystal reports or if it  is a desktop app then use the WinAPI::ShellExecute() method to open it. Look at the document management control in Ax to see how it opens word/pdf documents within ax.

  • Ahmed Muhammad Alam Profile Picture
    3,089 on at
    RE: Calling Crystal Report from AX 2012 R2

    any suggestion

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Mea_ Profile Picture

Mea_ 4

#3
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans