Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

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

*This post is locked for comments

  • 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,278 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,278 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,278 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,278 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');

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