Home > Dynamics Ax > Displaying the Standard Ax report in EP pages of AX – Part – II

Displaying the Standard Ax report in EP pages of AX – Part – II


In this example, we will see how we will pass the parameters to the Report Query object from EP pages.

We will display the Customer report in EP pages of Dynamics Ax, based on the filter condition of customer account.

For this example, I will continue with my previous article.

http://paruvella.spaces.live.com/blog/cns!F2EC589E221A4DB0!509.entry

 

For the class, PSReportRunFromEP add the following things.

New methods:

public CustAccount setCustAccount(CustAccount _custAccount)

{

    ;

    custAccount = _custAccount;

    return custAccount;

}

 

protected void initQuery()

{

;

//in this method, I am going to change the Query by adding filters to the Report Query   

     report = new Report(reportName);       //reportName = “Cust”

    query = new Query(report.query());     // here I will get the Report Query def into query obj.

    query.dataSourceTable(tableNum(CustTable)).rangeField(fieldNum(CustTable, AccountNum)).value(custAccount);  //passing the value

 

}

 

Modify methods:

public static void reportToPDFFile(CustAccount _custAccount)

{

    PSReportRunFromEP reportRunFromEP = new PSReportRunFromEP();

    ;

    reportRunFromEP.setCustAccount(_custAccount);

    reportRunFromEP.initValue();

    reportRunFromEP.reportRun();

}

 

void initValue()

{

    ;

 

    //same lines from prev. article, just add the following line at the end 

    this.initQuery();

}

 

void reportRun()

{

    …. //Same lines from prev. article

    reportRun.query(query);                                   //Uncomment this line from my prev. article

    …….

}

 

Make sure that above class is added in Proxies.

Need to update the Proxies definition from Tools àDevelopment Tools àWeb Development àProxies and click on the Generate button.

 

Now we will develop the required Web parts

 

Web Part –I

    <table border="0">

      <tr>

      <td>

      <div id="divCustomer" runat="server">

    <asp:Label ID="LabelCustomer" runat="server" class="AxGroupHeaderCell" Width="0%"

        Text="<%$ AxLabel:@SYS24704 %>"> </asp:Label>

    <asp:TextBox runat="server" ID="TextBoxFilterCustAccount" Rows="1"></asp:TextBox>

    <dynamics:AxLookup ID="AxLookupFilterCustAccount" AutoPostBack="true" runat="server"

        ExtendedDataType="CustAccount" TargetControlId="TextBoxFilterCustAccount" Visible="true"

        SelectField="AccountNum" LookupType="EDT" >

        <Fields>

            <dynamics:AxBoundField DataField="AccountNum" SortExpression="AccountNum" />

            <dynamics:AxBoundField DataField="Name" SortExpression="Name" />

            <dynamics:AxBoundField DataField="NameAlias" SortExpression="NameAlias" />

        </Fields>

    </dynamics:AxLookup>

    <asp:Button ID="ReportButton" runat="server" Text="Report"

            onclick="ReportButton_Click" />

</div>   

    </td>

    </tr>

    </table>

 

C# Code — Code behind

using Microsoft.Dynamics.Framework.BusinessConnector.Session;

using ApplicationProxy = Microsoft.Dynamics.Portal.Application.Proxy;

using Proxy = Microsoft.Dynamics.Framework.BusinessConnector.Proxy;

public partial class EPCustReportHostl : System.Web.UI.UserControl

{

    private ISession AxSession

    {

        get

        {

            AxBaseWebPart webpart = AxBaseWebPart.GetWebpart(this);

            return webpart == null ? null : webpart.Session;

        }

    }

 

    protected void Page_Load(object sender, EventArgs e)

    {

     

 

    }

    protected void ReportButton_Click(object sender, EventArgs e)

    {

        //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, TextBoxFilterCustAccount.Text);

 

AxUrlMenuItem url = new AxUrlMenuItem("EPCustomerReport"); // This URL is for displaying the report in PDF file       

HttpContext.Current.ApplicationInstance.CompleteRequest();

        Response.Redirect(url.Url.OriginalString, false);

 

    }

}

 

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

 

Web Part –II

Nothing to design here, just add the following code in the Page_Load() method of web part

public partial class EPCustomerReportsl : System.Web.UI.UserControl

{

    protected void Page_Load(object sender, EventArgs e)

    {

        FileInfo fi = null;

 

        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 (EPCustomerReport.aspx), import the URL definition in to the Ax AOT.  We will refer same web menu item URL in first web part of button click event.

 

Now open the page EPCustomerReportHost from the Sales module of EP and page will be displayed as follows.

 

Select the customer and click on Report button on the same page.  Customer 2003 details will be displayed in next page as a PDF file.

 

 

This way we can pass the parameters from EP pages to the standard reports.

 

i.e. exactly, how we have the parameters for the reports in Ax client, same behavior we can bring for the EP reports also, and we can generate similar reports from EP as well.

Advertisements
Categories: Dynamics Ax
  1. KESHAV
    May 14, 2010 at 1:22 pm

    Hi Santhosh,You are the man. One of the superb & best blogs i have ever seen. I generally go through all your blogs very frequently and i get answers for most of my tasks from your blogs. It worked perfectly fine for me. I did only a samll change in my .net code for the above example. I just added one more Response.Flush(); line after Response.WriteFile(fi.FullName); (This code comes in the second webpart .net code). It worked well.Keep blogging which helps people like us.You are Rocking Star of AX, EP and .net.Keep it up.Thanks.Keshav (Accenture)

  2. Hani
    June 23, 2010 at 12:20 pm

    Hi Santosh,Very good article and great work around report conditioning. I really like it.Keep it up Santosh 🙂

  3. Paul
    October 27, 2011 at 7:21 am

    Hi Santosh,
    Really nice article. but one small doubt. in your article you write that report print PDF. could you tell me how to directly call that Ax standard ssrs report with parameter.

    for example. created one SSRS report with parameter. that report working inside that client. but same report how we call (with parameter)

    could you please guide me.

    Thanks in advance

  4. Paul
    October 27, 2011 at 7:23 am

    Paul :Hi Santosh,Really nice article. but one small doubt. in your article you write that report printing in PDF. could you tell me how to directly call that Ax standard ssrs report with parameter in EP.
    for example. created one SSRS report with parameter. that report working inside that client. but same report how we call (with parameter) in EP
    could you please guide me.
    Thanks in advance

  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: