Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

A currency to convert from is required to retrieve exchange rate information while printing the report in pdf format using code

(0) ShareShare
ReportReport
Posted on by 506

Hello all,

This is my code to print a report to pdf format.

public static void main(Args _args)
{
SrsReportRunController controller = new SrsReportRunController();
CustTransOpenPerDateContract contract = new CustTransOpenPerDateContract();
SrsReportEMailDataContract emailContract = new SrsReportEMailDataContract();
ExchangeRateHelper exchangeRateHelper = new ExchangeRateHelper();
SRSPrintDestinationSettings settings;

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

controller.parmExecutionMode(SysOperationExecutionMode::ScheduledBatch);

controller.parmShowDialog(false);
exchangeRateHelper.parmFromCurrency(“USD”);

controller.parmReportContract().parmRdpContract(contract);

settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.overwriteFile(true);
settings.fileName(@’C:\Users\sst_siddhant\Desktop\PDFfile.pdf’);

controller.startOperation();
}
I am getting an error –
1.A currency to convert from is required to retrieve exchange rate information.
2.Microsoft.Dynamics.Ax.Xpp.ErrorException: Exception of type ‘Microsoft.Dynamics.Ax.Xpp.ErrorException’ was thrown.
What will be the solution for this issue.

Thank You
Siddhant Singh

*This post is locked for comments

  • Martin Dráb Profile Picture
    Martin Dráb 231,321 Most Valuable Professional on at
    RE: A currency to convert from is required to retrieve exchange rate information while printing the report in pdf format using code.

    I suggest you use the debugger to find out what's wrong. Probably a certain record doesn't have any currency code filled it.

    I don't have any AX 2012 environment on hand, so I can't look even statically at the code. The code in D365FO is very different; line numbers from AX 2012 are useless there.

  • Siddhant Singh Profile Picture
    Siddhant Singh 506 on at
    RE: A currency to convert from is required to retrieve exchange rate information while printing the report in pdf format using code.

    Yes, Sorry its my mistake.

  • Martin Dráb Profile Picture
    Martin Dráb 231,321 Most Valuable Professional on at
    RE: A currency to convert from is required to retrieve exchange rate information while printing the report in pdf format using code.

    You've attached the tag "Microsoft Dynamics AX (current version)" and you posted the same question under by blog post about printing in D365FO, but the screenshot is actually from AX 2012, isn't it?

  • Siddhant Singh Profile Picture
    Siddhant Singh 506 on at
    RE: A currency to convert from is required to retrieve exchange rate information while printing the report in pdf format using code.

    Martin,

    ErrorPdf.png

    This two errors I am getting. Can you please tell me how to remove it.

  • Martin Dráb Profile Picture
    Martin Dráb 231,321 Most Valuable Professional on at
    RE: A currency to convert from is required to retrieve exchange rate information while printing the report in pdf format using code.

    If I remove unused variables and format your code, I get this:

    public static void main(Args _args)
    {
        SrsReportRunController controller = new SrsReportRunController();
        CustTransOpenPerDateContract contract = new CustTransOpenPerDateContract();
        SRSPrintDestinationSettings settings;
        
        controller.parmReportName(ssrsReportStr(FreeTextInvoice, Report));
        controller.parmExecutionMode(SysOperationExecutionMode::ScheduledBatch);
    controller.parmShowDialog(false); controller.parmReportContract().parmRdpContract(contract);
    settings = controller.parmReportContract().parmPrintSettings(); settings.printMediumType(SRSPrintMediumType::File); settings.fileFormat(SRSReportFileFormat::PDF); settings.overwriteFile(true); settings.fileName(@'C:\Users\sst_siddhant\Desktop\PDFfile.pdf'); controller.startOperation(); }

    Notice that you never set any values of the contract.

    Also, if it's for D365Fo (as the version tag says), there is no point in specifying the path. The web server can't write on your local disk; it'll give you the file for download.

    To fix your problem, first find out where the exception is thrown from.

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,321 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans