Pages

Thursday, June 4, 2015

AX 2012 Enterprise Portal: Create SSRS Report for EP

Noted:  This content is based on AX 2012 R2 + CU7 


It's been really long time, right?   I was so busy with company's projects and focused on other modules instead of Retail.  These days, I have to do Enterprise Portal with showing SSRS report.  Someone asks me to prepare guideline for colleagues.  So, just have idea to write in here too.    

Scenario: 

Create new SSRS Report to show on Enterprise Portal.  

Pages: 

Payroll Pay Statement is simplest example to start with.   

  • Go to:  Employee Services > Personal infomation > Pay stetements

To have SSRS on EP, there are 2 main pages

  • List page for sending report parameters



  • SSRS Viewer page  



Prepare SSRS Report: 


  • Temporary table 
    • TableType = InMemory
  • Report Data Provider Class (DP) 
    • Extends SRSReportDataProviderBase
  • Output MenuItem
    • RunOn = Server




Report Viewer: 

Web Control to support Report Viewer must extend AxBaseUserControl.  Set Output MenuItems in AxReportViewer.    

      <dynamics:AxReportViewer runat="server" ID="MyReport" MenuItemName="PayrollEPWorkerPayStatement" /> 

In code behind, page_init method.   Send parameters to report.  Below is example when parameter is from RecId. 

        protected void Page_Init(object sender, EventArgs e)
    {
        Dictionary<string, object> parms = new Dictionary<string,object>();

        int tableId = AxQueryString.GetCurrent(Page).WTID;
        KeyValuePair<int, string> kv1 = ControlHelper.DecryptWKEY(AxQueryString.GetCurrent(Page));

        Int64 payStatementRecId = 0;

        if (kv1.Value != null)
        {
            payStatementRecId = Int64.Parse(kv1.Value, CultureInfo.InvariantCulture);
        }

        // Add params required for report when accessed from EP
        parms.Add("PayrollPayStatementReport_PayStatement", payStatementRecId);

        //
        // Must add blank versions of the other variables in the data contract
        // even though they are not used when report is accessed from EP.
        //
        parms.Add("PayrollPayStatementReport_PayCycle", 0);
        parms.Add("PayrollPayStatementReport_PayPeriod", 0);
        parms.Add("Disbursement", "blank");
        parms.Add("PrintContributions", true);

        // Add the parameters to the report control 
        this.MyReport.AddParameters(parms);
    } 

But if parameter is from a field in dataset.  Need to get record from AxQueryString first.   Add below functions to get current record.  

       /// <summary>
    /// Get AxQueryString for the current page
    /// </summary>
    private AxQueryString AxQueryString
    {
        get
        {
            return AxQueryString.GetCurrent(this.Page);
        }
    }

    private ISession AxSession
    {
        get
        {
            AxBaseWebPart webpart = AxBaseWebPart.GetWebpart(this);
            return webpart == null ? null : webpart.Session;
        }

    }

Then in page_init, use IAxaptaRecordAdapter to get the record entity from AxQueryString.   

    Dictionary<string, object> parms = new Dictionary<string, object>();

    string itemId = ""; 

    if (this.AxQueryString != null && this.AxQueryString.RecordContext != null)
    {
        IAxaptaRecordAdapter entityRecord = null;
        entityRecord = this.AxQueryString.RecordContext.DataKey.GetRecord(this.AxSession);

        if (entityRecord != null)
        {
            itemId = (string)entityRecord.GetField("ItemId");
        }

    }

Noted:  Add reference as below for IAxaptaRecordAdapter. 

using Microsoft.Dynamics.AX.Framework.Services.Client;
using Microsoft.Dynamics.Framework.BusinessConnector.Session;
using Microsoft.Dynamics.Framework.BusinessConnector.Adapter;

Once a Web Control is created, there will be a Managed Web Content with same name.   You can deploy it here (right click > Deploy to EP).   



New Web URL MenuItem and Page Definitions will be created in AOT and deployed to EP.  


MenuItems: 

The list page can be Web Control or AX List Page form.  The most important is MenuItems.  There are 2 main MenuItems: -

  • Web URL MenuItem to open report viewer page 
  • Output MenuItem to call the report.



If the list page is Web Control, add AxHyperLinkBoundField for the Web URL MenuItem.   

      <dynamics:AxHyperLinkBoundField DataField="PaymentDate" DataSet="HcmEPWorkerPayStatementList" DataSetView="PayrollPayStatement"
                SortExpression="PaymentDate" MenuItem="PayrollEPWorkerPayStatement">                     
      </dynamics:AxHyperLinkBoundField>

If the list page is AX ListPage, set the Web URL MenuItem in HyperLinkMenuItem and HyperLinkDataSource (example from SalesTableListPage).





Reference: 

If you are beginner for Enterprise Portal, you may start it from Microsoft Dynamics AX 2012 White Paper: Enterprise Portal Development Cookbook.   There is everything in the white paper already.   I just gather about SSRS here.  Hope it helps you.