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




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



3 Responses to How to Set the Query Range on a SSRS Report

  1. oslebeto says:

    Thank for your answer,

    In this moment, i doing the test, I want send automatically a report by mail and i want take the mail of the customer that is set in the query, but this process is by code, because the user set a range of customer and system have to send a report to which one of the customers parametrized in the query, where I can change this functionality for to send the email?

    thanks very much…you know that the change between Ax 2009 and AX2012 is very large in reports!!

  2. I use SrsReportRunController to call Query or RDP report in X++ Code.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: