SSRS Report using Controller , Contract and RDP class in Ax 2012 R2 & Validates fromDate and ToDate Value

Hi All,

Today I would like to share you ,  how to create SSRS report using Controller, Contract and RDP class in AX 2012 R2?

Step 1:

Create new Temp Table . Ex: VendTransTemp with below listed table.



Step 2 :

Create a New Class . Ex: SRDemoDP which extends SRSReportDataProviderBase




  

[SRSReportParameterAttribute(classStr(SRDemoContract))]
 
class SRDemoDP extends SRSReportDataProviderBase
{
    SRDemoContract contract;
    VendTransTemp  vendTransTmp;
}
 
 
 [SRSReportDataSetAttribute('VendTransTemp')]
public VendTransTemp getTmpVendTransDetails()
{
    select * from vendTransTmp;
    return vendTransTmp;
}
 
 
[SysEntryPointAttribute]
public void processReport()
{

     Query query;

    QueryRun qRun;

    QueryBuildRange qbr,qbr1;

    VendTrans    vendTrans;

    AccountNum vendAccountNum;

    date fromDate,toDate;

    contract = this.parmDataContract() as SRDemoContract;

    vendAccountNum=contract.parmVendAccountNum();

    fromDate=contract.parmfromDate();

    toDate=contract.parmtoDate();

     query =  new Query();

    query.addDataSource(tableNum(VendTrans)).addRange(fieldNum(VendTrans,TransDate)).value(queryRange(fromDate,toDate));
    qRun = new QueryRun(query);

     while(qRun.next())

    {
        vendTrans = qRun.get(tableNum(VendTrans));

        if(vendTrans.AccountNum==vendAccountNum)

        {

            vendTransTmp.AmountMST=vendTrans.AmountMST;

            vendTransTmp.VendAccount=vendTrans.AccountNum;

            vendTransTmp.VendInvoiceId=vendTrans.Invoice;

            vendTransTmp.Voucher=vendTrans.Voucher;

            vendTransTmp.TransDate=vendTrans.TransDate;

            vendTransTmp.insert();

        }
    }
}
 
Step 3:
 
Create a New Class . Ex: SRDemoContract class which implements SysOperationValidatable Interface .
 
 
class SRDemoContract implements SysOperationValidatable

{

AccountNum vendAccountNum;
TransDate formDate,toDate;

}

 
 

[DataMemberAttribute('FromDate')]

 
public FromDate parmfromDate(TransDate _formDate = formDate)

{

formDate= _formDate;
 
return formDate;
 }

 

 

[DataMemberAttribute('ToDate')]
 public ToDate parmtoDate(TransDate _toDate = toDate)

{

toDate= _toDate;
return toDate;

}

 
[DataMemberAttribute('AccountNum')]

public AccountNum parmVendAccountNum(AccountNum _vendAccountNum = vendAccountNum)
{

vendAccountNum= _vendAccountNum;
return vendAccountNum;

}



public boolean validate()
 {
 boolean isValid = true;

if (!formDate)

{
  isValid = checkFailed("From Date should be entered");

}
  if (!toDate)
 
{
  isValid = checkFailed("To Date should be entered");

}
 if (isValid && (formDate > toDate))
  
{
  isValid = checkFailed(strfmt("From Date should be less than or equal to To Date", date2StrUsr(formDate, DateFlags::FormatAll), date2StrUsr(toDate, DateFlags::FormatAll)));

}
  return isValid;

}


Step 4:

 
Create a New Class . Ex: SSRSDemoController class which extends SRSReportRunController.
 




class SSRSDemoController extends SrsReportRunController
{
}
 protected void prePromptModifyContract()
{

 
VendTable vendTable;

SRDemoContract contract;

FormDataSource fds;
  //get the reference of the current contract object

contract = this.parmReportContract().parmRdpContract() as SRDemoContract;

vendTable=Args.record();

fds=Args.record().dataSource();

contract.parmVendAccountNum(vendTable.AccountNum);
 

}  public static client void main(Args args)
{
//define the new object for controller class
SSRSDemoController ssrsDemoController;
 ssrsDemoController = new SSRSDemoController();

//pass the caller args to the controller
ssrsDemoController.parmArgs(args);
 //set the report name and report design to run
ssrsDemoController.parmReportName(ssrsReportStr(Controller_SSRS,PrecisionDesign1));

//execute the report
srsDemoController.startOperation();

} 


Step 5:

Design the report in Visual studio. Add the report to AOT and deploy it

Step 6:

Create Output menuitem for the SSRs Report

Step 7:

Create action menuitem for the controller class . Ex: SSRSDemoController

Step 8 :

Add the menuitem to VendorTableListPage form




Step 9:

Click Vendor Transaction Report Button . A Parameter window open with the selected vendor Account Number.




     
  Ouput :


Comments

Post a Comment

Popular posts from this blog

AX7/D365/Operations: Enable/Disable form control in X++

AX 2012: Multi-Select Lookup for SSRS Report Dialog

Credit limit check on Sales Quotation based on the customer credit limit in D365 FO of AX7