SSRS Report UI Builder class in Ax 2012

Description:-

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.

Sample UI Builder Class

·         Create a new class. Open AOT à Classes.
·         Right Click on Classes and select New Class. Name it as ItemTransactionSummaryUIB.
·         Open the Class declaration by right clicking on it and selecting View code.
·         Write the following code.

Class ItemTransactionSummaryUIB extends SysOperationAutomaticUIBuilder
{

}

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.

[DataContractAttribute,
    SysOperationContractProcessingAttribute(classstr(ItemTransactionSummaryUIB))]
class ItemTransactionSummaryContract implements SysOperationValidatable
{

}

Examples of UI Builder Class Usage

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

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:

Public void build()
{
    ItemTransactionSummaryContract   contract;

    contract = this.dataContractObject() as ItemTransactionSummaryContract;

    dialogFromDate    = this.addDialogField(methodStr(ItemTransactionSummaryContract, ParmFromDate),contract);
    dialogToDate      = this.addDialogField(methodStr(ItemTransactionSummaryContract, ParmToDate),contract);
    dialogItemId      = this.addDialogField(methodStr(ItemTransactionSummaryContract, parmItemId),contract);
    dialogItemGroupId = this.addDialogField(methodStr(ItemTransactionSummaryContract, parmItemGroup),contract);
    dialogDiamension  = this.addDialogField(methodStr(ItemTransactionSummaryContract, parmDiamension),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(ItemTransactionSummaryContract,parmCustGroupId));

    //register the method we want to override
    dlgCustGroup.registerOverrideMethod(
          methodStr(FormStringControl, lookup),
          methodStr(ItemTransactionSummaryUIB,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.

Also you can create lookup using the AOT query and use in UI Builder class like below.

I have used below AOT query to get ItemGroupId for creating lookup in SSRS report.

 

UI Builder class declaration

class ItemTransactionSummaryUIB extends SysOperationAutomaticUIBuilder
{
    DialogField                    dialogItemGroupId;
    ItemTransactionSummaryContract ItemTransactionSummaryContract;
}

Build method

public void build()
{
    ItemTransactionSummaryContract   contract;
    contract = this.dataContractObject() as ItemTransactionSummaryContract;
 dialogItemGroupId = this.addDialogField(methodStr(ItemTransactionSummaryContract, parmItemGroup),contract);
}

PostBuild method

public void postBuild()
{
    ItemTransactionSummaryContract   contract;
    super();
    contract = this.dataContractObject() as ItemTransactionSummaryContract;
    dialogItemGroupId = this.bindInfo().getDialogField(contract,methodStr(ItemTransactionSummaryContract, parmItemGroup));
    dialogItemGroupId.registerOverrideMethod(methodStr(FormStringControl, lookup),
        methodStr(ItemTransactionSummaryUIB, ItemGroupLookup),this);
    if (dialogItemGroupId)
    {
        dialogItemGroupId.lookupButton(2);
    }
}

Lookup method

private void ItemGroupLookup(FormStringControl _control1)
{
    Query       query;
    container   conItemGroup;

    query = new Query(queryStr(dev_ItemTransSumItemGroupQry));
    SysLookupMultiSelectGrid::lookup(query,_control1,_control1,conItemGroup);
}

If you have check box and you want to enable/disable other control based on the checkbox tick you also can do using the UI Builder class.

class ItemTransactionSummaryUIB extends SysOperationAutomaticUIBuilder
{
    DialogField                    dialogDiamension;
    ItemTransactionSummaryContract ItemTransactionSummaryContract;
}

public void build()
{
    ItemTransactionSummaryContract   contract;
    contract = this.dataContractObject() as ItemTransactionSummaryContract;
    
    dialogDiamension = this.addDialogField(methodStr(ItemTransactionSummaryContract, parmDiamension),contract);
}

public void postBuild()
{
    ItemTransactionSummaryContract   contract;
    super();
    contract = this.dataContractObject() as ItemTransactionSummaryContract;
 
    dialogDiamension  = this.bindInfo().getDialogField(contract, methodstr(ItemTransactionSummaryContract, parmDiamension));
    dialogDiamension.registerOverrideMethod(methodstr(FormCheckBoxControl, modified),
        methodstr(ItemTransactionSummaryUIB, dialoggetDiamension), this);
    //dialogToDate.enabled(any2enum(dialogDiamension.value()));
    if (dialogDiamension)
    {
        dialogDiamension.value();
    }
}

public boolean dialoggetDiamension(FormCheckBoxControl _checkBoxControl)
{
    ;
    if(any2enum(dialogDiamension.value()) == true)
    {
      //return true;
      //dialogToDate.enabled(any2enum(dialogDiamension.value()));
    }
    else
    {
      //return false;
    }
    //set enabled or disabled based on checkbox
    dialogFieldTransDate.enabled(any2enum(dialogFieldAllowModifyDate.value()));

    //or alternatively
    dialogFieldTransDate.enabled(_checkBoxControl.checked());

    return true;
}

Related Posts

Previous
Next Post »

Thanks for comments.....