Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Passing a parameter to an SSRS report from Controller

Posted on by

Hi folks, I need to run a batch job that passing the customer account to the SSRS report Dynamically...and this will write a PDF file per customer.

So I believe I need to call the controller class something like this:

But not sure how to pass the parameter to the report.  The parameter is not in the contract class.  Can't I just pass the parameter to the report by modifying the query range rather than adding the parameter to the contract class?

Thank you in advance...

SrsReportRunController controller = new SrsReportRunController();
SRSPrintDestinationSettings printSettings;

// set report name
controller.parmReportName(ssrsReportStr(AMKcustsevenDayOpen, Report));

controller.parmArgs().parm('custaccount?');

// get print settings from contract
printSettings = controller.parmReportContract().parmPrintSettings();

// set print medium
printSettings.printMediumType(SRSPrintMediumType::File);
printSettings.fileFormat(SRSReportFileFormat::PDF);
printSettings.overwriteFile(true);
printSettings.fileName(@"C:\Temp\Report.pdf");

// suppress the parameter dialog
controller.parmShowDialog(true);

// start operation
controller.startOperation();

Categories:
  • Suggested answer
    Mohamed lotfi Profile Picture
    Mohamed lotfi 255 on at
    RE: Passing a parameter to an SSRS report from Controller

    You can use the next code:-

    SrsReportRunController controller = new SrsReportRunController();

    SRSPrintDestinationSettings printSettings;

    SrsReportDataContract   contract;

    YourReportContractClass rdpContractClass;

    // set report name

    controller.parmReportName(ssrsReportStr(AMKcustsevenDayOpen, Report));

    //------  add this section-------//

    contract = controller.parmReportContract();

    rdpContractClass= contract.parmRdpContract() as YourReportcontractClass ;

    rdpContractClass.parmAccountNum(CustTable.AccountNum);

    //--------------//

    // get print settings from contract

    printSettings = controller.parmReportContract().parmPrintSettings();

    // set print medium

    printSettings.printMediumType(SRSPrintMediumType::File);

    printSettings.fileFormat(SRSReportFileFormat::PDF);

    printSettings.overwriteFile(true);

    printSettings.fileName(@"C:\Temp\Report.pdf");

    // suppress the parameter dialog

    controller.parmShowDialog(true);

    // start operation

    controller.startOperation();

  • brianmaric Profile Picture
    brianmaric on at
    RE: Passing a parameter to an SSRS report from Controller

    Thank You!!

    ...but is there any way to suppress the other required parameters?  I tried running it and got an error message saying date parameters are required.  I guess I could just create another design without the parameters but I wonder if there is a way around it.

    Thanks again!

  • Verified answer
    Mea_ Profile Picture
    Mea_ 60,274 on at
    RE: Passing a parameter to an SSRS report from Controller

    Example is in LedgerJournalController.main(), however, you don't need to do a straight copy, it's just an example, change it according to your needs.

  • brianmaric Profile Picture
    brianmaric on at
    RE: Passing a parameter to an SSRS report from Controller

    Thanks!!

    ...but how do you call it?

  • Suggested answer
    Mea_ Profile Picture
    Mea_ 60,274 on at
    RE: Passing a parameter to an SSRS report from Controller

    It is possible, look at LedgerJournalController.setRange() method and it's usage.

  • brianmaric Profile Picture
    brianmaric on at
    RE: Passing a parameter to an SSRS report from Controller

    It is a query based report and Ideally I don't want to add a parameter to the contract class...possible?

  • Mea_ Profile Picture
    Mea_ 60,274 on at
    RE: Passing a parameter to an SSRS report from Controller

    It's depends how it's done. Is it query based report ? Do you have data contract ?

  • brianmaric Profile Picture
    brianmaric on at
    RE: Passing a parameter to an SSRS report from Controller

    oh...so you just can't pass the parameter to the report query...

  • Suggested answer
    Mea_ Profile Picture
    Mea_ 60,274 on at
    RE: Passing a parameter to an SSRS report from Controller

    Hi brianmaric,

    You need to get data contract and set parameter there, something like

    AMKcustsevenDayOpenContract rdpContract = controller.parmReportContract().parmRdpContract() as AMKcustsevenDayOpenContract ;

    rdpContract .parmCustAccount('blah-blah');

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,263 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,112 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans