8/08/2016

How to run SSRS report from X++ code in AX? 2. SrsReportRunController

SrsReportRunController is new in AX2012. It extends the SysOperation framework.
Here's a sample.

SrsReportRunController 

SrsReportRunController controller;
;
//Initilize
controller = new SrsReportRunController();
//Set report name.
controller.parmReportName(ssrsReportStr(Test, PrecisionDesign1));

//Run report
controller.startOperation();

To set parameter

  • If the data source type is Report Data Provider, we need to use the a data contract instance to set parameter. See sample below,
//Initilize
controller = new SrsReportRunController();
//Set report name.
controller.parmReportName(ssrsReportStr(Test, PrecisionDesign1));
//Get data contract instance.
rdpContract = controller.parmReportContract().parmRdpContract() as TestDataContract;
//Set parameter value;
rdpContract.parmSalesId('so-000050');
controller.startOperation();

  • If the data source type is Query, and the dynamic filer is turned off, we can set the parameter thru a RDL contract instance.
//Initilize
controller = new SrsReportRunController();
//Set report name.
controller.parmReportName(ssrsReportStr(Test, PrecisionDesign1));
//Get data contract instance.
rdpContract = controller.parmReportContract().parmRdpContract() as TestDataContract;
//Set parameter value;
rdpContract.parmSalesId('so-000050');
controller.startOperation();

  • If the data source type is Query, and the dynamic filter is turned on, we need to get the query of the report and set range to that query.

//Initilize
controller = new SrsReportRunController();
//Set report name.
controller.parmReportName(ssrsReportStr(Test, PrecisionDesign1));
//Get data contract instance.
query = controller.parmReportContract().parmQueryContract().lookup('Dataset1_DynamicParameter');
//Set parameter value;
query.dataSourceNo(1).clearRange();
query.dataSourceNo(1).addRange(fieldNum(SalesTable, SalesId)).Value('so-000050');

controller.startOperation();

Remember: parmQueryContract() returns the map of the queries, and we can lookup by the parameter name

Run  multiple reports to screen

When printing multiple reports to screen in code, the previous printed report will block the next one, untill user closes the previous one, the next one starts rendering. This is anoying if user needs to print multiple reports to screen as a batch. The solution to this is pretty simple, we just need to create a class to extend SrsReportRunController and overwrite the methods dialogShow and dialogClose. See sample below,

protected void dialogShow()
{
    SysOperationDialog sysOperationDialog;
    FormRun formRun;

    if (useReportViewerForm)
    {
        dialog.run();
        this.dialogPostRun();

        sysOperationDialog = dialog as SysOperationDialog;
        formRun = sysOperationDialog.formRun();
        formRun.detach();
    }
    else
    {
        super();
    }
}



protected void dialogClose()
{
    if(!useReportViewerForm)
    {
        super();
    }
}


1 comment:

  1. Hi, I have a problem in the Main method:
    "controller.parmReportName (ssrsReportStr (CORP_PazySalvoActivosFijos_Report, Report);" but when compiling I get the following error "The method operand is not an element"

    ReplyDelete