Tracing Auto-Prints

Help me help myself here, I’m trying to write code that will auto-print labels. I keep seeing people saying to run a trace to get the settings relevant to the specific report, but when I run a trace of the standard Auto Print I’m trying to reproduce with code I see no reference to the print process. Is it maybe because it’s running from a data directive? I have all the tracing boxes checked except Persist Tracing Options and Track Changes Only.

If I leave system monitor on I see the job referenced there, but if I shut it off I don’t even see the bpm referenced at all. Is there a way to get the info I need?

Are the labels being run through the 5 standard report printing functions or via some other method? Can you show us how you’re printing?

Hey I just realized I wasn’t clear that I’m trying to trace a standard Auto Print so I can reproduce it with code. The Auto Print looks like this:

That you wouldn’t be able to do from a BPM. You would need to find a way to print it from the client to do a trace. What you can do is enable source generation for BPMs, save your BPM, go to the server BPM sources folder and see what they are doing.

I created a quick BPM for test. Using PackSlip report and the settings below
image

It generates code like below in that folder I referenced earlier. Looking at it, there are way easier ways but I don’t know what will work in your situation.

private void A001_AutoPrintAction()
        {
            var reportParamTS = new Erp.Tablesets.PackingSlipPrintTableset();
            var reportParamTable = reportParamTS.PackingSlipParam;
            var reportParamRow = new Erp.Tablesets.PackingSlipParamRow();
            reportParamTable.Add(reportParamRow);
        
            int rowIndex = 0;
        
            Ice.Lib.Trace.AutoPrintTrace rootAutoPrintTracer = new Ice.Lib.Trace.AutoPrintTrace();
            rootAutoPrintTracer.AddRootTraceMessage("Processing AutoPrint action for Report 'PackSlip', Style 'Standard - SSRS'");
            rootAutoPrintTracer.AddToTraceHandler();
        
            rootAutoPrintTracer.AddSettingTraceMessage("PrintSchedule", "Queue");
            rootAutoPrintTracer.AddSettingTraceMessage("PrintAction", "AutoPrnt");
            
            Ice.Lib.Trace.AutoPrintTrace rowSpecificAutoPrintTracer = null;
            foreach (var primaryTableRow in this.ttABCCode.Where(r => (!r.Unchanged() || (r.Unchanged() && !ttABCCode.Any(r1 => r1.SysRowID == r.SysRowID && r1.RowMod != r.RowMod)))))
            {
                rowSpecificAutoPrintTracer  = new Ice.Lib.Trace.AutoPrintTrace(rootAutoPrintTracer);
                rowSpecificAutoPrintTracer.AddRootTraceMessage(null, "ProcessRow");
                rowSpecificAutoPrintTracer.AddRootToParent(); 
        
                rowSpecificAutoPrintTracer.AddRowTraceMessage(rowIndex, primaryTableRow.SysRowID);
        
                SetUIBasedReportParameters_A001_AutoPrintAction(reportParamRow, primaryTableRow);
                
                reportParamRow.AutoAction =  "SSRSPrint" ;
                reportParamRow.ReportStyleNum = 2 ;
                reportParamRow.WorkstationID = Session.TaskClientID?? string.Empty; 
                if (reportParamTable.Columns.Contains("ReportID"))
                {
                    reportParamRow["ReportID"] = "PackSlip" ;
                }
        
                reportParamRow.TaskNote = "";
                reportParamRow.SSRSRenderFormat = "PDF";
        
                
                
                string printerName = "\\\\server\\printer\";
                string printerSettings = "PrinterName=\"\\\\server\\printer\",Copies=10,Collate=True,Duplex=Default,FromPage=1,ToPage=0";
                string pageSettings  =  "Color=True,Landscape=False,AutoRotate=False,PaperSize=[Kind=\"Letter\" PaperName=\"Letter\" Height=1100 Width=850],PaperSource=[SourceName=\"FormSource\" Kind=\"FormSource\"],PrinterResolution=[Kind=\"Custom\" X=600 Y=600]";
        
                reportParamRow.PrinterName = printerName;
                reportParamRow.RptPrinterSettings = printerSettings;
                reportParamRow.RptPageSettings = pageSettings;
        
                rowSpecificAutoPrintTracer.AddSettingTraceMessage("PrinterName", printerName);
                rowSpecificAutoPrintTracer.AddSettingTraceMessage("PrinterSettings", printerSettings);
        
                rowSpecificAutoPrintTracer.AddLinqRowTraceMessage(reportParamRow, "ReportParameter");
        
                if (String.IsNullOrEmpty ("Erp.Contracts.PackingSlipPrintSvcContract"))
                {
                    Epicor.Hosting.Trace.ServerLog.WriteTraceMessage(Epicor.Hosting.Trace.WellKnownTraceFlags.BpmTrace, "BPM.AutoPrint", () =>"Report class name is empty" );
                    throw new Ice.Common.BusinessObjectException("Report class name is empty");
                }
            
                var reportService = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.PackingSlipPrintSvcContract>(Db, true);
                if (reportService == null)
                {
                    throw new Ice.Common.BusinessObjectException("Report service 'Erp.Contracts.PackingSlipPrintSvcContract' not available");
                }
                
                // Submit to agent (Queued)
                try
                {
                    // 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:"Erp.Services.Rpt.PackingSlipPrint");
        
                    rowSpecificAutoPrintTracer.AddTraceMessage("Report submitted", "QueueMode");
                }
                catch (Exception ex)
                {
                    Epicor.Hosting.Trace.ServerLog.WriteTraceMessage(
                    Epicor.Hosting.Trace.WellKnownTraceFlags.BpmTrace, 
                    "BPM.AutoPrint", 
                    () => "SubmitToAgent failed. Ex: {0}" + ex.ToString());
        
                    // handle errors here
                    throw new Ice.Common.BusinessObjectException("Failed to submit autoprint report. Error: " + ex.ToString());
                }
        
                rowIndex++;
            }
        }
        
        private void SetUIBasedReportParameters_A001_AutoPrintAction(Erp.Tablesets.PackingSlipParamRow reportParamRow, ABCCodeTempRow primaryTableRow)
        {
            reportParamRow.PackNum = Convert.ToInt32("0");
            reportParamRow.PrintingOptions = Convert.ToString("S");
            reportParamRow.AssignLegalNumber = Convert.ToBoolean("False");
            reportParamRow.EnableAssignLegalNumber = Convert.ToBoolean("False");
            reportParamRow.StyleNumExt = Convert.ToInt32("1008");
            reportParamRow.EnableIncludePCID = Convert.ToBoolean("False");
            reportParamRow.IncludePCID = Convert.ToBoolean("False");
            reportParamRow.DraftMode = Convert.ToBoolean("False");
            reportParamRow.IncludeInventoryAttributes = Convert.ToBoolean("False");
            reportParamRow.ArchiveCode = Convert.ToInt32("0");
            reportParamRow.DateFormat = Convert.ToString("m/d/yyyy");
            reportParamRow.NumericFormat = Convert.ToString(",.");
            reportParamRow.PrintReportParameters = Convert.ToBoolean("False");
            reportParamRow.SSRSEnableRouting = Convert.ToBoolean("True");
            reportParamRow.DesignMode = Convert.ToBoolean("False");
        }
1 Like

I’ll see if I can harvest enough from your example to make something work. We’re a cloud customer so I can’t get at the server for those.

The BPM running server side makes sense as a reason I can’t trace the print.

When you do that print is it coming out on SSRS or are you using BarTender or something else?

We’re using bartender.

If that is the case I would write the BPM to just send custom BAQ data straight to BarTender and bypass Epicor auto print feature. It’s so much easier in the long run, more flexible, you can add custom logic to the print. It’s why we got rid of auto-print. Nice place to start but as things get more complex BAQs are so much easier to manage than RDD

1 Like

Do you have some sample code for that, that you would be willing to share? That does sound a lot better than what I’m trying to do.

I also just realized that, as a cloud customer, we might have a more complicated method of reaching bartender than you do. We have to have files dropped on Epicor’s FTP and bartender monitors that folder for new files. Bartender is on prem and Epicor is in their cloud so they can’t directly interface.