我需要找到一种方法来打印"一个SrsReport
,在我的情况下为SalesInvoice
,作为.PDF(或任何类型的文件)到特定位置。
为此,我修改了SRSPrintDestinationSettings
以将SalesInvoice-Report输出为.PDF:
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.overwriteFile(true);
settings.fileName(@'\\AXDEV\Bottomline\Test\test.pdf');
不知何故,这会被忽略,我会收到一封电子邮件,其中附有.PDF报告。
例如,这将在ax 2012上运行,但不会为我打印到PDF。
SRSPrintDestinationSettings settings;
CustInvoiceJour custInvoiceJour;
SrsReportRunController controller = new SrsReportRunController();
PurchPurchaseOrderContract rdpContract = new PurchPurchaseOrderContract();
SalesInvoiceContract salesInvoiceContract = new SalesInvoiceContract();
select firstOnly1 * from custInvoiceJour where custInvoiceJour.SalesId != "";
// Define report and report design to use
controller.parmReportName(ssrsReportStr(SalesInvoice,Report));
// Use execution mode appropriate to your situation
controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
rdpContract.parmRecordId(custInvoiceJour.RecId);
controller.parmReportContract().parmRdpContract(rdpContract);
// Explicitly provide all required parameters
salesInvoiceContract.parmRecordId(custInvoiceJour.RecId); // Record id must be passed otherwise the report will be empty
controller.parmReportContract().parmRdpContract(salesInvoiceContract);
salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo()); // comment this code if tested in pre release
// Change print settings as needed
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.overwriteFile(true);
settings.fileName(@'\\AXDEV\Bottomline\Test\test.pdf');
//tokens = settings as SrsPrintDestinationTokens();
//controller.parmPrintDestinationTokens(null);
//Suppress report dialog
controller.parmShowDialog(false);
// Execute the report
controller.startOperation();
问题: 这是将srsReport打印到.pdf的正确方法吗? 我正确地传递/设置了printerSettings吗? 它在哪里说"发送电子邮件"?
编辑:代码工作正常。我们使用的公司的外部代码根本没有实现这一点。 使用Alex Kwitny的清洁代码
答案 0 :(得分:6)
这是我的工作代码。我只是根据你的方式快速编写了这个从头开始/内存编码,所以比较差异。
我有两个标记为(1)和(2)的东西供您尝试使用您的代码,或者只是复制/粘贴我的。
static void JobSendToPDFInvoice(Args _args)
{
SrsReportRunController controller = new SrsReportRunController();
SRSPrintDestinationSettings settings;
CustInvoiceJour custInvoiceJour = CustInvoiceJour::findRecId(5637925275);
SalesInvoiceContract salesInvoiceContract = new SalesInvoiceContract();
Args args = new Args();
controller.parmReportName(ssrsReportStr(SalesInvoice, Report));
controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
controller.parmShowDialog(false);
salesInvoiceContract.parmRecordId(custInvoiceJour.RecId);
salesInvoiceContract.parmDocumentTitle(CustInvoiceJour.InvoiceId);
salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());
// (1) Try by passing args
args.record(custInvoiceJour);
args.parmEnum(PrintCopyOriginal::Original);
args.parmEnumType(enumNum(PrintCopyOriginal));
controller.parmReportContract().parmRdpContract(salesInvoiceContract);
controller.parmArgs(args);
// (2) Try explicitly preventing loading from last value
// controller.parmLoadFromSysLastValue(false);
// Change print settings as needed
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.overwriteFile(true);
settings.fileName(@'C:\Temp\Invoice.pdf');
controller.startOperation();
}
答案 1 :(得分:1)
由于您正在讨论销售发票,报表正在使用打印管理功能,您不能简单地覆盖此类打印设置。
您需要覆盖控制器类上的runPrintMgmt
并确定是否需要默认的打印管理或您自己的代码。
请参阅此帖子以获取示例:http://www.winfosoft.com/blog/microsoft-dynamics-ax/manipulating-printer-settings-with-x