web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
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 518

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

I have the same question (0)
  • Martin Dráb Profile Picture
    239,660 Most Valuable Professional on at

    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.

  • Siddhant Singh Profile Picture
    518 on at

    Martin,

    ErrorPdf.png

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

  • Martin Dráb Profile Picture
    239,660 Most Valuable Professional on at

    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
    518 on at

    Yes, Sorry its my mistake.

  • Martin Dráb Profile Picture
    239,660 Most Valuable Professional on at

    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.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 21

#2
dekion Profile Picture

dekion 4

#2
Virginia99 Profile Picture

Virginia99 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans