Printing a BAQ Report from an Epicor Function

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++;
    }
    

Here are the errors:

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!

1 Like

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.

1 Like

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.

@cschrempp were you able to print it from bpm?

No, I have not been able to get it to work.

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);

if (hBAQReport != null)
{
  baqReportDS = hBAQReport.GetNewBAQReportParam("MLMESTickets");
  
  var baqReportParamR = baqReportDS.BAQReportParam.FirstOrDefault(x => x.RowMod.Equals("A"));
  if (baqReportParamR != null)
  {
    filter1 = "<DynamicReportDataSet xmlns=" + @"""http://www.epicor.com/Ice/300/BO/DynamicReport/DynamicReport""" + "><BAQReport><Company>28597</Company><BAQRptID>MLMESTickets</BAQRptID><Description>MES Tickets</Description><ReportTitle /><FormTitle>MES Tickets</FormTitle><ExportID>ML_CustomMtlTags_CR8</ExportID><SystemFlag>false</SystemFlag><GlobalReport>false</GlobalReport><IsCrystalReport>false</IsCrystalReport><ReportID>MLMESTickets</ReportID><CrystalReportName /><CGCCode /><SSRSReportName>ML_MESTickets_CR8.rdl</SSRSReportName><SysRevID>76966550</SysRevID><SysRowID>3f095fe3-f5b0-4d73-ad38-dfcc73e8a5b1</SysRowID><TempRowID /><BitFlag>0</BitFlag><RowMod /></BAQReport><BAQRptOptionFld><Company>28597</Company><BAQRptID>MLMESTickets</BAQRptID><DataTableID>JobHead</DataTableID><FieldName>JobNum</FieldName><CompOp>=</CompOp><Seq>1</Seq><DefaultValue /><FieldLabel>Job</FieldLabel><DisplayName>JobHead_JobNum</DisplayName><FieldFormat>x(14)</FieldFormat><EpiGuid>7d026358-87da-41e3-99cc-8cf0cf3a09f2</EpiGuid><IsVisible>true</IsVisible><DataType>nvarchar</DataType><SystemFlag>false</SystemFlag><DispOrder>0</DispOrder><SysRevID>76968028</SysRevID><SysRowID>043b9f6c-460f-4983-8f68-5e8695659678</SysRowID><FieldValue>000180</FieldValue><TempRowID>Field1</TempRowID><BitFlag>0</BitFlag><RowMod /></BAQRptOptionFld><BAQRptOptionFld><Company>28597</Company><BAQRptID>MLMESTickets</BAQRptID><DataTableID>JobOper</DataTableID><FieldName>AssemblySeq</FieldName><CompOp>=</CompOp><Seq>2</Seq><DefaultValue /><FieldLabel>Asmbl</FieldLabel><DisplayName>JobOper_AssemblySeq</DisplayName><FieldFormat>&gt;&gt;&gt;9</FieldFormat><EpiGuid>c7cd19e3-8194-429c-b166-7396d0302a05</EpiGuid><IsVisible>true</IsVisible><DataType>int</DataType><SystemFlag>false</SystemFlag><DispOrder>0</DispOrder><SysRevID>76968029</SysRevID><SysRowID>13f38a60-facc-42f9-8ee4-fb2db0f933c5</SysRowID><FieldValue>0</FieldValue><TempRowID>Field2</TempRowID><BitFlag>0</BitFlag><RowMod /></BAQRptOptionFld><BAQRptOptionFld><Company>28597</Company><BAQRptID>MLMESTickets</BAQRptID><DataTableID>JobOper</DataTableID><FieldName>OprSeq</FieldName><CompOp>=</CompOp><Seq>3</Seq><DefaultValue /><FieldLabel>Opr</FieldLabel><DisplayName>JobOper_OprSeq</DisplayName><FieldFormat>&gt;&gt;&gt;9</FieldFormat><EpiGuid>fa761d71-ce89-48eb-9a81-ab9258f1f74d</EpiGuid><IsVisible>true</IsVisible><DataType>int</DataType><SystemFlag>false</SystemFlag><DispOrder>0</DispOrder><SysRevID>76968030</SysRevID><SysRowID>16a7e107-a332-4acf-8cfc-badc8257d9c3</SysRowID><FieldValue>10</FieldValue><TempRowID>Field3</TempRowID><BitFlag>0</BitFlag><RowMod /></BAQRptOptionFld><BAQRptOptionFld><Company>28597</Company><BAQRptID>MLMESTickets</BAQRptID><DataTableID>ReportParam</DataTableID><FieldName>Character01</FieldName><CompOp>=</CompOp><Seq>4</Seq><DefaultValue /><FieldLabel>Character01</FieldLabel><DisplayName>ReportParam_Character01</DisplayName><FieldFormat /><EpiGuid>9e8ed869-1312-42ab-b91d-d8d53160315d</EpiGuid><IsVisible>true</IsVisible><DataType>nvarchar</DataType><SystemFlag>false</SystemFlag><DispOrder>0</DispOrder><SysRevID>77159983</SysRevID><SysRowID>4a3276c5-5a3e-4f39-8bdc-3a07e58ed30f</SysRowID><FieldValue /><TempRowID>Field4</TempRowID><BitFlag>0</BitFlag><RowMod /></BAQRptOptionFld></DynamicReportDataSet>";     
    
    workstation = Session.ClientComputerName + " " + Session.ClientTerminalID;
    
    baqReportParamR.BAQID = "ML_CustomMtlTags_CR8";
    baqReportParamR.ReportTitle = "MES Tickets";
    baqReportParamR.Filter1 = filter1;
    baqReportParamR.UserID = Session.UserID;
    baqReportParamR.BAQRptID = "MLMESTickets";
    baqReportParamR.ReportID = "MLMESTickets";
    baqReportParamR.AutoAction = "SSRSPREVIEW"; //Use "SSRSPREVIEW" to print preview, "SSRSClientPrint" for Client Printer or "SSRSPrint" for Server Printer
    //baqReportParamR.PrinterName = "PrinterName"; //User this if SSRSClientPrint or SSRSPrint options are used
    InfoMessage.Publish("jobNum " + jobNum);
    InfoMessage.Publish("asmbl " + asmbl);
    InfoMessage.Publish("oprSeq " + oprSeq);
    baqReportParamR.Option01 = jobNum;
    baqReportParamR.Option02 = asmbl;
    baqReportParamR.Option03 = oprSeq;
    baqReportParamR.Character01 = Session.EmployeeID;
    baqReportParamR.Number01 = ttReportQtyR.CurrentQty;
    baqReportParamR.WorkstationID = workstation;
    baqReportParamR.ReportStyleNum = 1;
    baqReportParamR.AgentID = "SystemTaskAgent";
  }
  hBAQReport.SubmitToAgent(baqReportDS, "SystemTaskAgent", 0, 0, "Ice.UIRpt.BAQReport;MLMESTickets");    
}
hBAQReport = null;

For the AutoPrintHandler use this - Note Ice.Lib.Trace

var autoPrintHandler = new Ice.Lib.Trace.AutoPrintHandler(Db);

Thank you, which assembly did you use? I didn’t find the Ice.Lib.Trace

Thanks!

Instead of

var reportService = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.BAQReportSvcContract>(Db, true);

Use this

    CallService<Ice.Contracts.BAQReportSvcContract>(bq => {
    // Perform Code
    });
3 Likes

Thank you, that worked! The only thing I’m hung up on now is the Ice.Lib.Trace not being found in the function.

That was wrong it was in Ice.Lib. Let me grab the right thing and post shortly.

Add Ice.Lib.BAM

        CallService<Ice.Lib.AutoPrintHandler>(ap => {
               reportParamRow.Filter1 = ap.BuildBAQReportCriteriaDocumentAndUpdateReportParameters("ETK_RMA_Trav", reportParamRow, prompts, filters);
        });
2 Likes

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.

@cschrempp if you are using a function you need to add the assembly into References > Assemblies

image

And use ErpContext() to replace Db

1 Like

I had both of those assemblies added and tried your ErpContext suggestion but I’m still getting the error with the AutoPrintHandler.

I ended up just moving it to a BPM instead of a function so that I could get the report to print.

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);

Hope this helps someone else in the future.
Brett

1 Like