Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

SRSReportServerWarmup - Setting dynamic parameter value(s)

Posted on by 4,070

I am adding several reports to the SRSReportServerWarmup class to help speed up reports that are run [nearly] every day.  One of the reports requested to be added to the warmup list is the Purchase receiving log report (VendPurchReceivingLog_NA).  This report has no RDP, so I copied the "runSampleRdlReportWithParameters" method, as I want to add a value to the Delivery Date parameter and run it for the past 30 days.  However, this report runs from a view, which pulls from a query that has the DeliveryDate and PurchId dragged into the Range field, which automatically pulls these to the front when running the report for a user to select.  While the fields are displayed for entry, they are not hard-fast "parameters".  They are included in the AX Dynamic parameter "VendPurchReceivingLog_DynamicParameter".  

So, using the provided sample code:

   // Set any required parameter values here by first getting the report contract.

   contract = controller.parmReportContract();

   // And then fill in that contract based on the contract type (Rdl or Rdp)

   // Create the Rdl contract and set parameter values

   rdlDataContract = contract.parmRdlContract();

   rdlDataContract.setValue('<Parameter1Name>', '<Parameter1Value>');

   rdlDataContract.setValue('<Parameter2Name>', '<Parameter2Value>');

...how can I add in my DeliveryDate parameter into the dynamic parameter?  

*This post is locked for comments

  • Verified answer
    Andy Adamak Profile Picture
    Andy Adamak 4,070 on at
    RE: SRSReportServerWarmup - Setting dynamic parameter value(s)

    After some research and trial & error, I've found a solution.  You can add dynamic parameter values to a report in X++ using the method below.  It can be pasted into the SRSReportServerWarmup Class to be used like the other 'runSample' methods.  Just copy the code and replace the appropriate fields under the "// Retrieve the query map and set dynamic parameter values" section.  Note that if the datasource is not found on the query the report will still execute with no parameters.  Handling this situation could vary by report, so handle it on a per-report basis.  

    /// <summary>

    /// Sample method for running a simple report (non-RDP) that requires dynamic parameter values.

    /// </summary>

    /// <remarks>

    /// Use this method as a template for "warming-up" any simple SQL Server Reporting Services report.

    /// </remarks>

    public void runSampleReportWithDynamicParameters()

    {

       str reportFilePath;

       Map                             queryContracts;

       MapEnumerator                   meQueryContracts;

       Query                           currentQuery;

       QueryBuildDataSource            dataSource;

       SrsReportDataContract contract;

       SrsReportRdlDataContract rdlDataContract;

       // Create a controller to run the report.

       SrsReportRunController controller = new SrsReportRunController();

       // set the report name and design to be run

       controller.parmReportName('SampleReportName.DesignName');

       // suppress the parameter dialog as this is to be run by the batch service

       controller.parmShowDialog(false);

       // choose to save the executed report as a pdf file

       reportFilePath = System.IO.Path::Combine(this.getTempPath(), 'SampleReportName.DesignName' + #FileExtensionPDF);

       this.setReportRunControllerPrintToFile(controller, reportFilePath);

       // Set any required parameter values here by first getting the report contract.

       contract = controller.parmReportContract();

       // Retrieve the query map and set dynamic parameter values

       queryContracts = contract.parmQueryContracts();

       if(queryContracts)

       {

           meQueryContracts = queryContracts.getEnumerator();

           while(meQueryContracts.moveNext())

           {

               currentQuery = meQueryContracts.currentValue();

               dataSource = currentQuery.dataSourceName("VendPurchReceivingLog_NA");

               if(dataSource)

               {

                   SysQuery::findOrCreateRange(dataSource,fieldNum(VendPurchReceivingLog_NA, DeliveryDate))

                             .value(date2StrXpp(systemDateGet()) + '..'

                                   + date2StrXpp(DateTimeUtil::date(DateTimeUtil::addDays(DateTimeUtil::utcNow(), -30))));

               }

               else

               }

                   // ???

               }

           }

       }

       // run the report

       controller.runReport();

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans