Saturday, 30 November 2013

Displaying the Standard Ax report in EP pages of AX

If we have scenario like, client not ready to adapt the SSRS, and he wants the report in EP pages of Dynamics Ax 2009. Eventually we need to use standard Ax reports for generating the reports.
Can we show the standard Ax reports in EP pages?
Yes, we can utilize the same standard Ax reports and can be displayed in the EP pages.
The following example will illustrate the same.
 Displaying the Standard Ax Customers report in EP pages.
 Create the following Class and add to the Proxies node.
 class PSReportRunFromEP
{
    Args                 reportArgs;
    ReportName           reportName;
    ReportRun            reportRun;
    Report               report;
    PrintJobSettings     printJobSettings;
    Query                query;
    CustAccount          custAccount;
}

void initValue()
{
    ;
    reportName = "Cust";
    reportArgs = new Args(reportName);
    reportArgs.name(reportName);
}

void reportRun()
{
    ;
    reportRun = new ReportRun(reportArgs);

    // Set printersettings
    printJobSettings = reportRun.printJobSettings();
    printJobSettings.setTarget(PrintMedium::File);
    printJobSettings.format(PrintFormat::PDF);
    printJobSettings.fileName("D:\Customers.pdf");
    printJobSettings.suppressScalingMessage(true);
   
    reportRun.report().interactive(false);
If we want add any filters to the query like passing customer account number, then we will use the following statement.
    //reportRun.query(query); 
    reportRun.query().interactive(false);
    reportRun.init();
    reportRun.run();
}
public static void reportToPDFFile()
{
    PSReportRunFromEP reportRunFromEP = new PSReportRunFromEP();
    ;
    reportRunFromEP.initValue();
    reportRunFromEP.reportRun();
}

static void main(Args args)
{
    ;
    PSReportRunFromEP::reportToPDFFile();
}

We can test the same, by executing the above class. PDF file will be generated with the customer details.

Development for EP:

Add the above class to the Proxies under  AOT àWebàWeb FilesàStatic FilesàProxies

/class:PSReportRunFromEP
    /method:PSReportRunFromEP.reportToPDFFile

 Create the new web part and add the following code to the web part:

using Microsoft.Dynamics.Framework.BusinessConnector.Session;
using System.IO;
using ApplicationProxy = Microsoft.Dynamics.Portal.Application.Proxy;
using Proxy = Microsoft.Dynamics.Framework.BusinessConnector.Proxy;

protected void Page_Load(object sender, EventArgs e)
    {
        FileInfo fi = null;

//calling the proxy method for generating the report into PDF file and the same report we are displaying in EP       
Microsoft.Dynamics.Portal.Application.Proxy.PSReportRunFromEP.reportToPDFFile(this.AxSession.AxaptaAdapter);
        fi = new FileInfo("D:\Customers.pdf");

        if (fi.Exists)
        {
            Response.Clear();
            Response.ContentType = "application/pdf";
            Response.Flush();
            Response.WriteFile(fi.FullName);
            Response.End();
           
        }
       
    }

Add this web part to the new page, import the URL definition in to the Ax AOT, and add this URL to web menus of Sales module.


This way, we can show the standard Ax reports in EP pages. Gift with a bow

No comments:

Post a Comment