I am trying to print a SSRS report from code, w/ no menu being popped up. When I run this bit of code from an AX job it works perfectly:
static void Job25(Args _args)
{
str _prodId='12345';
SrsReportRunController reportRunController;
myController parmData;
//get users default printer from User options
XX_PrinterName printerName = SysUserInfo::find().xx_PrinterName;
// Create the report run controller
reportRunController = new SrsReportRunController();
reportRunController.parmReportName(ssrsReportStr(reportName,report));
reportRunController.parmLoadFromSysLastValue(false);
// Set printer settings (you can print to file, format, filename, etc).
reportRunController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::Printer);
reportRunController.parmReportContract().parmPrintSettings().printerName(printerName);
parmData = new myController();
parmData.parmProdId(_prodId);
//set the execution mode to Synchronous
reportRunController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
reportRunController.parmReportContract().parmRdpContract(parmData);
// Run the report
reportRunController.run();
}
Info message: Report XXX was sent to printer "...printer name...."
I have this same bit of code in the ProdMultiSchedulingJob class, in the run method
// Only run when the Prod Order is not Stopped.
if (!WHSProdTable::find(prodParmScheduling.ProdId).Stopped)
{
// Only run when the Prod Order has no active work.
if(!WHSProdTable::isWorkActiveForProdOrder(prodParmScheduling.ProdId))
{
this.initProdTable(prodParmScheduling.ProdId).status().runJobScheduling(prodParmScheduling,false,prodPurch,this, wrkCtrScheduler);
//print here
XX_printSSRSRpeort(prodParmScheduling.ProdId);
}
else
{
warning("...");
}
}
In the SrsReportRunController class, run method...when invoking printerInfo it always returns null.
When the report is run from a menu it shows up fine, and the srsPrintDestSetting variable is exactly the same.
// If the printer is invalid, use the default printer instead.
srsPrintDestSettings = this.parmReportContract().parmPrintSettings();
if (srsPrintDestSettings != null)
{
printerHelper = new Microsoft.Dynamics.AX.Framework.Reporting.Shared.PrinterHelper();
printerInfo = printerHelper.GetPrinterInfo(srsPrintDestSettings.printerName()); //ALWAYS NULL When coming from ProdMulit class
// Check if the device is available
if (printerInfo == null)
{
// Use the default printer
printerSettings = new System.Drawing.Printing.PrinterSettings();
srsPrintDestSettings.printerName(printerSettings.get_PrinterName());
}
}
So in the job it will use the default printer the user selects in their options. But from the class it will default to OneNote2013.
Any ideas?
Thanks!
*This post is locked for comments
I have the same question (0)

Report
All responses (
Answers (