Bojensen Blogs

How to Set the Query Range on a SSRS Report | Amir's Microsoft Dynamics AX space


I found a couple of examples on how to set the QueryRange on SSRS reports on Amir’s AX Space

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




// Save the report settings.


// Run the report.;


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

reportQuery = new Query(querystr(CustPaymManOutputReport));
fieldnum(TmpPaymManOutputReport, SessionId),

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

How to Set the Query Range on a SSRS Report | Amir’s Microsoft Dynamics AX space

Comments are closed.