SBX - Search With Button

SBX - Forum Post Title

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

Microsoft Dynamics AX Forum

Siddhant Singh asked a question on 25 Nov 2018 10:30 AM
My Badges

Question Status

Unanswered

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

Reply

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.

Reply
Siddhant Singh responded on 25 Nov 2018 12:11 PM
My Badges

Martin,

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

Reply

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?

Reply
Siddhant Singh responded on 25 Nov 2018 12:24 PM
My Badges

Yes, Sorry its my mistake.

Reply

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.

Reply

SBX - Two Col Forum

SBX - Migrated JS