Friday, 26 June 2015

Creating a simple SSRS report with UI Builder,Controller,contract and DP class in Microsft Dynamisc AX 2012

Here are the steps:

>> UI Builder Class:

1. Create a new class. Open AOT à Classes, Right Click on Classes and select New Class. Name it as SSRSTestUIBuilder.
2.Open the Class declaration by right clicking on it and selecting View code.
3.Write the following code: 
public class SSRSTestUIBuilder extends SrsReportDataContractUIBuilder
{

}

>> Contract Class:

4. Now create a new class called Contract Class. Example: TestContract()

[SysOperationContractProcessingAttribute(classStr(SSRSTestUIBuilder))] //Important Line which connects UI Builder and contract class.
public class TestContract()
{

}

5.In contract class add the parameter methods.
Example: 
public CustAccoutn parmAccountNum(CustAccount AccountNum _AccountNum )
{       
         AccountNum = _AccountNum ;      
         return AccountNum ;
}

Note : Based on the requirements add as much as parameters methods needed.


>> Controller Class:


6.Create a controller class.
Example: 
public class SSRSTestController extends SrsReportRunController
{
//define the required declarations
}

7. Create a main method and write the following code:
public static client void main(Args args)
 {
    //define the new object for controller class
    SSRSTestController ssrsTestController;
    ssrsTestController = new SSRSTestController();
    //pass the caller args to the controller
    ssrsTestController.parmArgs(args);
    //set the report name and report design to run
    ssrsTestController.parmReportName(ssrsReportStr(SSRSSessionQuery,Design));
     //execute the report
    ssrsTestController.startOperation();
 }

>> Back to UI-BUILDER:

8. Based on different scenarios, different methods are overridden as shown:

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));   
}

also use this code in build method to bind data:

//get the report data contract object

contract = this.dataContractObject();
    
//associate dialog field with data contract method

this.addDialogField(methodStr(SSRSTestContract,parmCustAccount), contract);


9.Over-ride a lookup method:

public void lookupCustAccount(FormStringControl _formStringControl)
{   

    Query query = new Query();

    QueryBuildDataSource DS;  
  
    SysTableLookup sysTablelookup;

    //create a table lookup    

    sysTablelookup = SysTableLookup::newParameters(tableNum(CustTable),_formStringControl);

    sysTablelookup.addLookupfield(fieldNum(CustTable,AccoutNum));
    
    //create a query

    DS = query.addDataSource(tableNum(CustTable));

    DS.addRange(fieldNum(CustTable,AccoutnNum)).value('001');

    //assign the query and call lookup

    sysTablelookup.parmQuery(query);

    sysTablelookup.performFormLookup();
}


10.Now override the postBuild method:

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(SSRSTestContract,parmCustAccoutn));

    //register the method we want to override

    dlgCustGroup.registerOverrideMethod(

          methodStr(FormStringControl, lookup),

          methodStr(SSRSTestUIBuilder,lookupCustAccount),this);    

}

>> RDP(Report data provider):

Now create a class called TestDemoDP class, note that the name of the class must end with 'DP'.

(i) class declaration:

public TestDemoDP ()
{
   # define the required variables
   TempTable     tmpTable;
}

(ii) getTemporaryTable(): Here you need to create a temporary table (Go to AOT create a table and name it ''TempTable' and set the Table Type property as 'TempDB')

public TempTable getTemporaryTable()
{
   select * from tmpTable;
   return tmpTable;
}

(iii) processReport():

public void processReport()
{
     //Define Contract method
     //write the business logic as per scenarios
     while select AccountNum from custTable
              where custTable.AccountNum == '001';
    {
        //insert into temp table
        tmpTable.AccountNum = custTable.AccountNum;
        tmpTable.insert()l
    }  

}

Now you are ready with the fully loaded SSRS report which contains UI-Builder,contract,controller,and DP class.

Note: After having created all these you need to create design in visual studio and connect these code there.For more information refer my earlier blogs on SSRS reports.








No comments:

Post a Comment