I am trying to print a report using an Epicor function. I got a big head start from this helpful thread Printing a BAQ Report from an Epicor Function but I haven’t quite got it working so need some help.
The end goal here is to be able to print a QR code from a locally hosted website. I have a BAQ report setup in Epicor that users can run to print the QR code however that requires them to log into Epicor, navigate to the report, load the code to print, etc, etc, etc. We want to setup something super easy. eg hit this big button with forehead and QR code will come out here
So I have the BAQ report, all good there. I have made an Epicor function where I am trying to send a task to the system agent to print the BAQ report.
The task is queued up fine, it runs but no QR code is printed and no errors are reported anywhere (I have checked the SSRS logs, Task agent events, SQL logs, Epicor system monitor,).
I can see that the dataset has been created in the reporting database, I can even run the report manually using that dataset with the GUID so the data is good.
From the SSRS logs I can see the report was executed. So it looks like the task agent has done what it needs to do. The logs for a manually run report look the same as the log for a report triggered with the function.
If I run the report manually the only difference I can see in all the logs etc is that the system monitor has the report details when I run it manually and there is nothing when run from the function. Does this indicate SSRS is not returning the report back to the task agent??
So i have figured it out. I had the autoAction set to “SSRSClientPrint”, which I think needs the system monitor to be running to see when SSRS has finished generating the report. As this was running in a function there was no system monitor looking for it. I changed the AutoAction to “SSRSPrint” which is server printing then it worked
This is the code we have working at the moment. Note there is some xml in the code, I think I sniffed that from Task tables in the database after triggering a print manually.
var reportParamTS = new Ice.Tablesets.BAQReportTableset();
var reportParamTable = reportParamTS.BAQReportParam;
var reportParamRow = new Ice.Tablesets.BAQReportParamRow();
reportParamTable.Add(reportParamRow);
var Db = new ErpContext();
Db.Connection.Open();
var prompts = new Dictionary<string, object>();
var filters = new Dictionary<string, IEnumerable<object>>();
// note: to find details of what parameters are needed look up the [SysTaskParam] table in the database for examples from Epicor.
reportParamRow.BAQID = Convert.ToString("EquipQR");
reportParamRow.ReportTitle = Convert.ToString("EquipQR");
reportParamRow.Summary = Convert.ToBoolean("False");
reportParamRow.AttachmentType = Convert.ToString("PDF");
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("EquipQR");
reportParamRow.ReportID = Convert.ToString("EquipQR");
reportParamRow.ReportStyleNum = Convert.ToInt32("1");
reportParamRow.ReportCultureCode = Convert.ToString("en-AU");
reportParamRow.ReportCurrencyCode = Convert.ToString("AUD");
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("1");
reportParamRow.DateFormat = Convert.ToString("d/mm/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");
// Code to generate filter1 xml is not working. Cant get the right xml so commening out and manually creating xml
//filters.Add("EquipID", new [] { "EQ002706"} );
//var autoPrintHandler = new Ice.Lib.AutoPrintHandler(Db);
//reportParamRow.Filter1 = autoPrintHandler.BuildBAQReportCriteriaDocumentAndUpdateReportParameters("EquipQR", reportParamRow, prompts, filters);
reportParamRow.Filter1 =
$@"<DynamicReportDataSet xmlns=""http://www.epicor.com/Ice/300/BO/DynamicReport/DynamicReport"">
<BAQReport>
<Company />
<BAQRptID>EquipQR</BAQRptID>
<Description>Equipment QR Code</Description>
<ReportTitle />
<FormTitle>EquipQR</FormTitle>
<ExportID>EquipQR</ExportID>
<SystemFlag>false</SystemFlag>
<Completed>false</Completed>
<GlobalReport>false</GlobalReport>
<IsCrystalReport>false</IsCrystalReport>
<ReportID>EquipQR</ReportID>
<CrystalReportName />
<CGCCode />
<SSRSReportName>EquipQR.rdl</SSRSReportName>
<SysRevID>1896791908</SysRevID>
<SysRowID>67908e2f-0e9c-4973-819d-963bc5444d33</SysRowID>
<TempRowID />
<BitFlag>0</BitFlag>
<RowMod />
</BAQReport>
<BAQRptFilter>
<Company>TMT</Company>
<BAQRptID>EquipQR</BAQRptID>
<DataTableID>Equip</DataTableID>
<FieldName>EquipID</FieldName>
<AdapterName>EquipAdapter</AdapterName>
<Seq>1</Seq>
<LookupField>EquipID</LookupField>
<FilterLabel>Equipment ID</FilterLabel>
<TabLabel>Equipment ID</TabLabel>
<DisplayName>Equip_EquipID</DisplayName>
<EpiGuid>a46dcf9a-7d8b-4bce-8fc7-f1e3ca3d99f8</EpiGuid>
<IsVisible>true</IsVisible>
<FilterField>EquipID</FilterField>
<SystemFlag>false</SystemFlag>
<DispOrder>0</DispOrder>
<DataType>nvarchar</DataType>
<SysRevID>1898025078</SysRevID>
<SysRowID>5e4129d6-7e16-4925-914f-b17e87a33c04</SysRowID>
<TempRowID>FilterList1</TempRowID>
<FilterValue>N'{this.EquipID}'</FilterValue>
<BitFlag>0</BitFlag>
<RowMod />
</BAQRptFilter>
</DynamicReportDataSet>";
reportParamRow.Filter2 = $"<Equip_EquipID>{this.EquipID}</Equip_EquipID>";
reportParamRow.AutoAction = "SSRSPrint" ;
reportParamRow.ReportStyleNum = 1 ;
reportParamRow.WorkstationID = Session.TaskClientID?? string.Empty;
if (reportParamTable.Columns.Contains("ReportID"))
{
reportParamRow["ReportID"] = "EquipQR" ;
}
reportParamRow.TaskNote = "";
reportParamRow.SSRSRenderFormat = "PDF";
string printerName = "\\\\SERVER.internal\\ZDesigner-ZT410-203dpi-ZPL-(SupervisorOffice)";
string printerSettings = "PrinterName=\"\\\\SERVER.internal\\ZDesigner-ZT410-203dpi-ZPL-(SupervisorOffice)\",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]";
string pageSettings = "Color=False,Landscape=False,PaperSize=[Kind=\"Custom\" PaperName=\"Custom\" Height=165 Width=181],PaperSource=[SourceName=\"Manual feed\" Kind=\"Manual\"],PrinterResolution=[Kind=\"Custom\" X=203 Y=203]";
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: "SystemAgent",
agentSchedNum:0,
agentTaskNum:0,
maintProgram:"Ice.Services.Rpt.BAQReport");