Has anyone been able to call a BAQ Report from an Epicor function and send it off to be printed?
This is code I have translated to an epicor function from the Auto Print widget on a data directive but I have a few odd errors I have not been able to sort out. Any help would be appreciated.
var reportParamTS = new Ice.Tablesets.BAQReportTableset();
var reportParamTable = reportParamTS.BAQReportParam;
var reportParamRow = new Ice.Tablesets.BAQReportParamRow();
reportParamTable.Add(reportParamRow);
int rowIndex = 0;
foreach (var primaryTableRow in this.Db.UD14.Where(r => (r.Key2 == serialNum)))
{
var prompts = new Dictionary<string, object>();
var filters = new Dictionary<string, IEnumerable<object>>();
prompts.Add("SerialNumber", serialNum);
reportParamRow.BAQID = Convert.ToString("ETK_RMA_Trav");
reportParamRow.ReportTitle = Convert.ToString("Depot RMA Traveller");
reportParamRow.Summary = Convert.ToBoolean("False");
reportParamRow.UserID = this.BaqConstants.CurrentUserID;
reportParamRow.Check01 = Convert.ToBoolean("False");
reportParamRow.Check02 = Convert.ToBoolean("False");
reportParamRow.Check03 = Convert.ToBoolean("False");
reportParamRow.Check04 = Convert.ToBoolean("False");
reportParamRow.Check05 = Convert.ToBoolean("False");
reportParamRow.Number01 = Convert.ToDecimal("0");
reportParamRow.Number02 = Convert.ToDecimal("0");
reportParamRow.Number03 = Convert.ToDecimal("0");
reportParamRow.Number04 = Convert.ToDecimal("0");
reportParamRow.Number05 = Convert.ToDecimal("0");
reportParamRow.BAQRptID = Convert.ToString("ETK_RMA_Trav");
reportParamRow.ReportID = Convert.ToString("ETK_RMA_Trav");
reportParamRow.Option01 = (serialNum);
reportParamRow.Check06 = Convert.ToBoolean("False");
reportParamRow.Check07 = Convert.ToBoolean("False");
reportParamRow.Check08 = Convert.ToBoolean("False");
reportParamRow.Check09 = Convert.ToBoolean("False");
reportParamRow.Check10 = Convert.ToBoolean("False");
reportParamRow.ArchiveCode = Convert.ToInt32("0");
reportParamRow.DateFormat = Convert.ToString("m/d/yyyy");
reportParamRow.NumericFormat = Convert.ToString(",.");
reportParamRow.SSRSRenderFormat = Convert.ToString("PDF");
reportParamRow.PrintReportParameters = Convert.ToBoolean("False");
reportParamRow.SSRSEnableRouting = Convert.ToBoolean("false");
reportParamRow.DesignMode = Convert.ToBoolean("False");
var autoPrintHandler = new Ice.Lib.AutoPrintHandler(Db);
reportParamRow.Filter1 = autoPrintHandler.BuildBAQReportCriteriaDocumentAndUpdateReportParameters("ETK_RMA_Trav", reportParamRow, prompts, filters);
reportParamRow.AutoAction = "SSRSClientPrint" ;
reportParamRow.ReportStyleNum = 1 ;
reportParamRow.WorkstationID = Session.TaskClientID?? string.Empty;
if (reportParamTable.Columns.Contains("ReportID"))
{
reportParamRow["ReportID"] = "ETK_RMA_Trav" ;
}
reportParamRow.TaskNote = "";
reportParamRow.SSRSRenderFormat = "PDF";
string printerName = "\\\\Peabody\\RICOH C3300 PCL6";
string printerSettings = "PrinterName=\"\\\\Peabody\\RICOH C3300 PCL6\",Copies=1,Collate=False,Duplex=Simplex,FromPage=1,ToPage=0";
string pageSettings = "Color=False,Landscape=False,PaperSize=[Kind=\"Letter\" PaperName=\"Letter\" Height=1100 Width=850],PaperSource=[SourceName=\"Auto Tray Select\" Kind=\"AutomaticFeed\"],PrinterResolution=[Kind=\"Custom\" X=600 Y=600]";
reportParamRow.PrinterName = printerName;
reportParamRow.RptPrinterSettings = printerSettings;
reportParamRow.RptPageSettings = pageSettings;
var reportService = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.BAQReportSvcContract>(Db, true);
// Submit to agent (Queued)
// Pass an agentTaskNum of zero to get a new task record created.
// Pass an agentSchedNum of zero to use the default 'Now' schedule.
reportService.SubmitToAgent(
reportParamTS,
agentID: "SystemTaskAgent",
agentSchedNum:0,
agentTaskNum:0,
maintProgram:"Ice.Services.Rpt.BAQReport");
rowIndex++;
}
The second error (CS1503) is in regards to the line:
var reportService = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.BAQReportSvcContract>(Db, true);
Been trying to get this to work a couple different ways in the new Epicor functions but they all seem to fail with the “cannot convert from EFx.Print.Implementation” error so any help or guidance would be appreciated!
Wouldn’t the “easiest” thing to do be create a DD on an unused UD table, with an Autoprint widget, and have the function code just update the UD table - which would trigger the Autoprint. You could even pass “paramters” for the autoprint widget, via the UD data. Things like: Report Style, Disable Routing, etc… Or any parameters the Autoprint widget can set.
Yes, that would most likely be the easiest way of doing this.
The reason why I wanted to make it a function was so that I can more easily generalize the use of it in the future for when I need to, for example, print a BAQ Report without using a DD.
While doing it from code is the proper way, the DD with autoprint could act as the “function”. The DD could have several conditions and paths to various autoprint widgets. With UD table fields that were updated driving the condition logic and passing parameters. When this functionality is needed again for a different BAQ Report, just add another condition to check for the new BAQ Report in the UD data, and branch to the appropriate AutoPrint.
I’m using this code and it is working the only thing I’m researching is a way to avoid hardcoding the filter1 variable (if you use this code you need to trace your baq report to modify the filter1 parameter otherwise you will get a No Record Selected error).
//Print Tickets Report
var baqReportDS = new Ice.Tablesets.BAQReportTableset();
Ice.Contracts.BAQReportSvcContract hBAQReport = null;
hBAQReport = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.BAQReportSvcContract>(Db);
Thank you, that allowed me to compile and test the function but now I’m getting a server side exception when I try to call it where it doesn’t seem to recognize the AutoPrintHandler. Any ideas?
Yeah - so this will be a no go in a Function. The rest works good. I don’t have a specific auto print example so kind of taking a swag. I am reviewing now and think there might be a way around this.
So with the help of this thread and some digging I managed to get a function to print a BAQReport.
There were a few things I had to change:
change the autoAction to “SSRSPrint” to use server side printing. Without this it run without error but nothing would print.
change the XML for filter1 for my report. I was able to get the required xml by running the report manually and then looking in the Ice.SysTaskParam table.
I commented out the AutoPrintHandler code as it wasn’t working for me. It might be an easier way to get the xml if I could get it working. While trying to get it working I used this code to run it.
var Db = new ErpContext();
Db.Connection.Open();
var autoPrintHandler = new Ice.Lib.AutoPrintHandler(Db);