How to Set the Query Range on a SSRS Report

If the SSRS report is build with AOT query

SRSReportRun reportRun = new SRSReportRun(‘Report1.AutoDesign1’);

// Create variables for setting the range for the query.

Query query;

QueryBuildDataSource queryBuildDataSource;

QueryBuildRange queryBuildRange;

int i;

// Check if the query will return data.

if (reportRun.init())

{

// Find the Cust query.

query = reportRun.reportQuery(‘Cust’); // query name of the report

if (query != null)

{

// Get the Customers data source.

queryBuildDataSource = query.dataSourceName(‘Customers’);

if (queryBuildDataSource != null)

{

queryBuildRange = queryBuildDataSource.addRange(fieldName2Id(queryBuildDataSource.table(), ‘AccountNum’));

queryBuildRange.value(‘4000’);

}

}

// Save the report settings.

reportRun.saveSettings();

// Run the report.

reportRun.run();

}

If the report is build with Data contract

Here is an example which comes from the AOT – Classes – CustPamnManOutputReportController – preRunModifyContract method:

protected void preRunModifyContract()

{

Query reportQuery;

SrsReportRdlDataContract rdlContract;

rdlContract = this.parmReportContract().parmRdlContract(); // may be some changes require here if the report is running from some job.

if (rdlContract.getValue(#reportParameter))

{

custPaymManFile.reportDate(systemdateget());

custPaymManFile.status(PaymManRemittanceStatus::Sent);

}

this.processReport(custPaymManFile);

reportQuery = new Query(querystr(CustPaymManOutputReport));

SRSReportHelper::addParameterValueRangeToQuery(

reportQuery,

tablenum(TmpPaymManOutputReport),

fieldnum(TmpPaymManOutputReport, SessionId),

this.currentSessionId());

this.parmReportContract().parmQueryContracts().insert(queryKey, reportQuery);

}

Playing with SSRS report in dynamics ax 2012

here is the simple code that i have created to print the SSRS report in dynamics ax 2012 from different scenarios.

How to print the SSRS report in dynamics ax 2012 from code.

    SrsReportRun srsReportRun;

    // initiate the report.
    srsReportRun = new SrsReportRun ("InventTruckTransactionReport.PrecisionDesign1");
    srsReportRun.init();
    srsReportRun.reportCaption("InventTruckTransactionReport.PrecisionDesign1");
    // set parameters name, value.
    srsReportRun.reportParameter("TruckTransDS_JournalId").value("000161_070");
    // suppress the dialog
    srsReportRun.showDialog(false);

    if( srsReportRun )
    {
        // run the report 
        srsReportRun.executeReport();
    }

How to save the SSRS report to PDF/HTML through code in dynamics ax 2012.

    SrsReportRun srsReportRun;

    srsReportRun = new SrsReportRun("InventTruckTransactionReport.PrecisionDesign1");

    srsReportRun.init();
    srsReportRun.reportCaption("InventTruckTransactionReport.PrecisionDesign1");
    srsReportRun.reportParameter("TruckTransDS_JournalId").value("000161_070");
    srsReportRun.showDialog(false);

    // Print to a file named ReportExample in HTML/PDF format.
    srsReportRun.printDestinationSettings().printMediumType(SRSPrintMediumType::File);
    srsReportRun.printDestinationSettings().fileFormat(SRSReportFileFormat::PDF);
    srsReportRun.printDestinationSettings().overwriteFile(true);
    srsReportRun.printDestinationSettings().fileName(@"C:\InventTruckTransactionReport.pdf");

    if( srsReportRun )
    {
        srsReportRun.executeReport();
    }
%d bloggers like this: