Using UI Builder Class to Develop SSRS Reports in Microsoft Dynamics AX 2012

UI Builder Class Overview

User Interface (UI) Builder Class is used to define the layout of the parameter dialog box that opens before a report is run in Microsoft Dynamics AX. It is used to add the customizations as well as additional fields in the dialog.

Following are the scenarios where UI Builder Class can be used:

  1. Grouping dialog fields
  2. Overriding dialog field events
  3. Adding a customized lookup to a dialog field
  4. Binding dialog fields with Report contract parameters
  5. Changing the layout of the dialog
  6. Adding custom controls to the dialog

To create a UI builder class, extend it with SrsReportDataContractUIBuilder.

Pre-requisites

  1. Microsoft Dynamics AX 2012
  2. Reporting services extensions must be installed in Dynamics AX
  3. Report contract class

Sample UI Builder Class

  1. Create a new class. Open AOT à Classes
  2. Right Click on Classes and select New Class. Name it as SSRSDemoUIBuilder

UI builder class example in microsoft dynamics ax 2012

  • Open the Class declaration by right clicking on it and selecting View code

UI builder class example in microsoft dynamics ax 2012

  • Write the following code
public class SSRSDemoUIBuilder extends SrsReportDataContractUIBuilder
{

}
  • Now open the contract class and add the following line to the header of the class. It will tell the contract class to build the parameter dialog. In other words, it will link the UI Builder Class with the contract class.
SysOperationContractProcessingAttribute(classStr(SSRSDemoUIBuilder))

Examples of UI Builder Class Usage

Based on different scenarios, different methods are overridden as shown in the following examples:

  1. Grouping the dialog fields/Changing the layout of the dialog/Adding custom controls to the dialog
  • To customize the layout and add custom fields, override the build as shown below:
public void build()
{
    DialogGroup dlgGrp;    

    //get the current dialog
    Dialog      dlg = this.dialog();       

    //make required modifications to the dialog
    dlgGrp = dlg.addGroup('Dates');  
    dlgGrp.columns(2);   
    dlg.addField(identifierStr(FromDate));
    dlg.addField(identifierStr(ToDate));    
        
    dlgGrp = dlg.addGroup('Customer');  
    dlg.addField(identifierStr(CustAccount));    
}
  • ThIS build method is called by the report framework to generate the layout of the dialog.
  • Binding dialog fields with Report contract parameters
  • Write the following code in the build method:
//get the report data contract object
contract = this.dataContractObject();
    
//associate dialog field with data contract method
this.addDialogField(methodStr(SSRSDemoContract,parmCustGroupId), contract);
  • Overriding dialog field events/Adding a customized lookup to a dialog field
  • To add a customized lookup or to override a control method, create a new method containing the business logic. The new method must have the same signature as the method you want to override.
  • Then, override the postBuild method and register the method to override with the new method created.
  • In the following example, the lookup method of a field is to be overridden. To do this, create a new method lookupCustGroup and add the following code:
public void lookupCustGroup(FormStringControl _formStringControl)
{    
    Query query = new Query();
    QueryBuildDataSource DS;    
    SysTableLookup sysTablelookup;

    //create a table lookup    
    sysTablelookup = SysTableLookup::newParameters(tableNum(CustGroup),_formStringControl);
    sysTablelookup.addLookupfield(fieldNum(CustGroup,CustGroup));
    sysTablelookup.addLookupfield(fieldNum(CustGroup,Name));

    //create a query
    DS = query.addDataSource(tableNum(CustGroup));
    DS.addRange(fieldNum(CustGroup,PaymTermId)).value('N030');

    //assign the query and call lookup
    sysTablelookup.parmQuery(query);
    sysTablelookup.performFormLookup();
}
  • Now, override the postBuild method and write the following code:
public void postBuild()
{
    DialogField dlgCustGroup;
    
    super();
    
    //get the field to override by providing the data contract object and the associated attribute/method
    dlgCustGroup = this.bindInfo().getDialogField(this.dataContractObject(),
                methodStr(SSRSDemoContract,parmCustGroupId));

    //register the method we want to override
    dlgCustGroup.registerOverrideMethod(
          methodStr(FormStringControl, lookup),
          methodStr(SSRSDemoUIBuilder,lookupCustGroup),
          this);    
}
  • bindInfo returns an object of type SysOperationUIBindInfo. It contains information about the dialog controls bounded to a report contract.
  • postBuild method is called when dialog is created.
Advertisements

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