Get the underlying SSRS Report Query, reset query , add your own ranges and execute report [Dynamics AX 2012, X++]

Below is the small code snippet to get the underlying query of the SSRS report, reset query, prompt the parameters form, add our own ranges and execute the report. You can customize the job as per your requirements. Below I have used CustBaseData.Report report and added my own range on customer group.
static void SR_ResetQueries_executeReport(Args _args)
    #define.reportName(‘CustBaseData.Report’// report Name
    QueryBuildRange queryBuildRange;
    QueryBuildDatasource queryBuildDatasource;
    SRSReportRun srsReportRun;
    Query reportRunQuery;
    srsReportRun = new SRSReportRun(#reportName);
    srsReportRun.resetQueries(); // reset the query
    reportRunQuery = srsReportRun.reportQueries().lookup(srsReportRun.currentQueryKey());
    if (srsReportRun.isInitialized() && srsReportRun.prompt()) // prompt the parameters form
        queryBuildDatasource = SysQuery::findOrCreateDataSource(reportRunQuery, tablenum(CustTable));
queryBuildRange = SysQuery::findOrCreateRange(queryBuildDatasource,  fieldnum(CustTable, CustGroup));

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.