Method Directive to Print Report to EdgeAgent

Hello All. I’ve cobbled together some BPM code (Thanks EpiUsers) to print a BAQ Report on a Post Processing Method directive. It appears to work great in terms of rendering the report (AutoAction = SSRSPREVIEW), but once I change the action to SSRSPRINT, the system properly attempts to send the doc to a printer and experiences an error.

In my case (Saas), I’m sending the doc to an Edge Agent network printer which we’ve setup for testing. The printer works AND, from a different routine, I’m sending a Job Traveler to the EdgeAgent printer with no problems.

However, I keep getting this error in System Monitor (the report IS submitted successfully):

The text of that message has led me to spend hours trying to figure out how to specify the printer in some different way.

The printer ID, in Printer Maintenance, is “Prt57@SRV-ISTEST2-EdgeAgent” and I’ve tried preceding the string with a $, a @, and just as a string. I can’t figure out how to satisfy this requirement.

Has anyone encountered this before?

Code:

      string bpmLotNum = callContextBpmData.ShortChar01;
      string dquote = "\""; 
      string inPrinter = "Prt57@SRV-ISTEST2-EdgeAgent"; // REFERENCE TO PRINTER
      var rptTs = dynamicReport.GetByID("SI-BAQRPT-LTag1");
      var baqRptDS = baqReport.GetNewBAQReportParam("SI-BAQRPT-LTag1");
      baqRptDS.BAQReportParam[0].BAQRptID = "SI-BAQRPT-LTag1";
      baqRptDS.BAQReportParam[0].BAQID = "SI-BAQRPT-PrtLotTag";
      baqRptDS.BAQReportParam[0].ReportID = "SI-BAQRPT-LTag1";
      baqRptDS.BAQReportParam[0].ReportStyleNum = 1001;
      baqRptDS.BAQReportParam[0].Option01 = bpmLotNum;
      baqRptDS.BAQReportParam[0].AutoAction ="SSRSPRINT";
      baqRptDS.BAQReportParam[0].PrinterName = inPrinter;
      baqRptDS.BAQReportParam[0].WorkstationID = "PRT57";
      baqRptDS.BAQReportParam[0].SSRSRenderFormat = "PDF";
      baqRptDS.BAQReportParam[0].AttachmentType = "PDF";
      baqRptDS.BAQReportParam[0].Summary = false;
      baqRptDS.BAQReportParam[0].RecurringTask = false;
      baqRptDS.BAQReportParam[0].SSRSEnableRouting = false;
      baqRptDS.BAQReportParam[0].ArchiveCode = 0;
      baqRptDS.BAQReportParam[0].AgentSchedNum = 0;
      baqRptDS.BAQReportParam[0].AgentID = "SystemTaskAgent";
      baqRptDS.BAQReportParam[0].AgentTaskNum = 0;
      baqRptDS.BAQReportParam[0].RowMod = "A";
      baqRptDS.BAQReportParam[0].RptPageSettings = "Color=False,Landscape=False,Margins=[Left=25 Right=25 Top=25 Bottom=25],PaperSize=[Kind=" + dquote + "Letter" + dquote + " PaperName=" + dquote + "Letter" + dquote + " Height=1100 Width=850],PaperSource=[SourceName=" + dquote + "Automatic Selection" + dquote + " Kind=" + dquote + "AutomaticFeed" + dquote + "],PrinterResolution=[Kind=" + dquote  + "Custom" + dquote + " X=600 Y=600]";

      baqRptDS.BAQReportParam[0].RptPrinterSettings = "PrinterName=\"" + inPrinter + "\",Copies=" + 1 + ",Collate=False,Duplex=Simplex,FromPage=1,ToPage=0";
1 Like

I know, @klincecum , it’s a head-scratcher primarily because it’s so darned specific - printing a BAQ report, VIA BPM, to an Edge-Agent printer. I’m not expecting too many “oh yeah! I’m doing the same thing” type responses.

My suspicion is that the error is one of Epicor’s generic messages that tend to obscure the real problem - like an incorrectly specified (or missing) parameter.

Well actually, this is very close to what I was looking at some old code for today with the system monitor.

So now when my brain works again, I’ll have to look at this closer, as it may be something I need.

Did you see this topic Print SSRS Report to EdgeAgent printer in SaaS environment
there was similar case.

2 Likes

Hi @Olga. Thanks for your response. I just revisited that journey (yes, that was my post), AND, it is from that post, and your solution, that caused me to suspect that something else may be wrong - something other than the printer name.

I checked all the quotes and escape delimiters (to the best of my knowledge, anyway) that were problematic last time, BUT, like that older post, this issue could be a malformed or missing parameter. It just isn’t obvious to me what is missing - especially since the error complains about the printer name.

For clarification (because I’ve been trying various permutations of the printer settings), the last test including the following:

      string inPrinter = $"Prt57@SRV-ISTEST2-EdgeAgent"; 
      baqRptDS.BAQReportParam[0].RptPrinterSettings = "PrinterName=\"" + inPrinter + "\",Copies=" + 1 + ",Collate=False,Duplex=Simplex,FromPage=1,ToPage=0";

I keep getting the same error: “Edge printer network path does not appear to be valid…”
Note that we are printing other documents using the Edge Agent fairly regularly, so I know the printer works with our cloud setup/Edge Agent.

string inPrinter = "Prt57@SRV-ISTEST2-EdgeAgent"; 
      baqRptDS.BAQReportParam[0].RptPrinterSettings = "PrinterName=" + inPrinter + ",Copies=" + 1 + ",Collate=False,Duplex=Simplex,FromPage=1,ToPage=0";

try this Edit: don’t try this, looking at the trace, it does have the quotes around the printer name.

The error mentions network path, not printer name, actually :thinking:. Is there stack trace for it?

1 Like

I don’t think that is right. Should have a number after it?

We don’t have server printing, so I could be off.

Could you post the complete code from the working one and the non-working one?

Olga, since the only error is listed in the System Monitor, I do not have a stack trace - as I would if I had an actual error dialog box.

Sometimes the log includes the stack trace. The image provided shows text past the end of the cell. Is it possibly in there?

Okay Kevin, here’s the NON-working code…

/* Print BAQ Report SI-BAQRPT-LTag1
*/

try
{
  using (Ice.Contracts.DynamicReportSvcContract dynamicReport = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.DynamicReportSvcContract>(Db))
  {
    using( Ice.Contracts.BAQReportSvcContract baqReport = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.BAQReportSvcContract>(Db) )
    {
      string bpmLotNum = callContextBpmData.ShortChar01;
      string dquote = "\""; 
      string inPrinter = $"Prt57@SRV-ISTEST2-EdgeAgent"; 
      var rptTs = dynamicReport.GetByID("SI-BAQRPT-LTag1");
      var baqRptDS = baqReport.GetNewBAQReportParam("SI-BAQRPT-LTag1");
      baqRptDS.BAQReportParam[0].BAQRptID = "SI-BAQRPT-LTag1";
      baqRptDS.BAQReportParam[0].BAQID = "SI-BAQRPT-PrtLotTag";
      baqRptDS.BAQReportParam[0].ReportID = "SI-BAQRPT-LTag1";
      baqRptDS.BAQReportParam[0].ReportStyleNum = 1001;
      baqRptDS.BAQReportParam[0].Option01 = bpmLotNum;
      baqRptDS.BAQReportParam[0].AutoAction ="SSRSPRINT";
      baqRptDS.BAQReportParam[0].PrinterName = "Prt57@edgeagent";
      baqRptDS.BAQReportParam[0].WorkstationID = "PRT57";
      baqRptDS.BAQReportParam[0].SSRSRenderFormat = "PDF";
      baqRptDS.BAQReportParam[0].AttachmentType = "PDF";
      baqRptDS.BAQReportParam[0].Summary = false;
      baqRptDS.BAQReportParam[0].RecurringTask = false;
      baqRptDS.BAQReportParam[0].SSRSEnableRouting = false;
      baqRptDS.BAQReportParam[0].ArchiveCode = 0;
      baqRptDS.BAQReportParam[0].AgentSchedNum = 0;
      baqRptDS.BAQReportParam[0].AgentID = "SystemTaskAgent";
      baqRptDS.BAQReportParam[0].AgentTaskNum = 0;
      baqRptDS.BAQReportParam[0].RowMod = "A";
      baqRptDS.BAQReportParam[0].RptPageSettings = "Color=False,Landscape=False,Margins=[Left=25 Right=25 Top=25 Bottom=25],PaperSize=[Kind=" + dquote + "Letter" + dquote + " PaperName=" + dquote + "Letter" + dquote + " Height=1100 Width=850],PaperSource=[SourceName=" + dquote + "Automatic Selection" + dquote + " Kind=" + dquote + "AutomaticFeed" + dquote + "],PrinterResolution=[Kind=" + dquote  + "Custom" + dquote + " X=600 Y=600]";

      baqRptDS.BAQReportParam[0].RptPrinterSettings = "PrinterName=\"" + inPrinter + "\",Copies=" + 1 + ",Collate=False,Duplex=Simplex,FromPage=1,ToPage=0";
      rptTs.BAQRptOptionFld[0].FieldValue = bpmLotNum;
      
      DynamicReportDataSet rptDs = new DynamicReportDataSet();
      
      DatasetAdapter.CopyTSTableToDataTable<BAQReportRow, DynamicReportDataSet.BAQReportDataTable>(rptTs.BAQReport, rptDs.BAQReport);
      DatasetAdapter.CopyTSTableToDataTable<BAQRptFilterRow, DynamicReportDataSet.BAQRptFilterDataTable>(rptTs.BAQRptFilter, rptDs.BAQRptFilter);
      DatasetAdapter.CopyTSTableToDataTable<BAQRptOptionFldRow, DynamicReportDataSet.BAQRptOptionFldDataTable>(rptTs.BAQRptOptionFld, rptDs.BAQRptOptionFld);
      DatasetAdapter.CopyTSTableToDataTable<BAQRptSortRow, DynamicReportDataSet.BAQRptSortDataTable>(rptTs.BAQRptSort, rptDs.BAQRptSort);
      DatasetAdapter.CopyTSTableToDataTable<BAQRptSortFldRow, DynamicReportDataSet.BAQRptSortFldDataTable>(rptTs.BAQRptSortFld, rptDs.BAQRptSortFld);
      
      rptDs.AcceptChanges();
      StringWriter writer = new StringWriter();
      rptDs.WriteXml(writer);
      baqRptDS.BAQReportParam[0].Filter1 = writer.ToString();
      
      baqReport.SubmitToAgent(baqRptDS, "SystemTaskAgent", 0, 0, "Ice.UIRpt.BAQReport;LotTag"); 
      writer.Dispose();
      baqReport.Dispose();
    }
    dynamicReport.Dispose();
  }
}
catch (Exception ex)
{
  this.PublishInfoMessage("An error occured trying to print report." + ex.Message, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
}

And here’s the working code…

/*Print Job Documents  -- Report styles 1002 SI-Traveler, 1003 SI-MO
String Print or Preview (SSRSPRINT,  SSRSPREVIEW)
Input parameters:
string inPrinter
string inJobs (tilde delimited string of jobnums)

Output parameters:
string output
*/
var context = Ice.Services.ContextFactory.CreateContext<ErpContext>(); 
using (var svcJobTrav = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.JobTravSvcContract>(context)) 
{ 
    // Set variables for use in the routine
    string strWkst = this.BaqConstants.WorkstationID;
    string dquote = "\""; 
    string prtAction = (inRenderType =="SSRSPRINT"?"SSRSPRINT":"SSRSPREVIEW");
    //inPrinter = @"Prt57@SRV-ISTEST2-EdgeAgent";       //  Comment this and the 3 addit'l lines below, when live
    //inJobs = "001237-1-1~001170-1-1";
    //string prtAction = "SSRSPRINT";
    string [] jobArray = inJobs.Split("~");
    Erp.Tablesets.JobTravTableset tsJobTrav = svcJobTrav.GetNewParameters();
    if (tsJobTrav != null) 
    {
      tsJobTrav.JobTravParam[0].PrntAllMassPrnt = false;
      tsJobTrav.JobTravParam[0].PrinterName = inPrinter;
      tsJobTrav.JobTravParam[0].BarCodes = true;
      tsJobTrav.JobTravParam[0].AutoAction = prtAction;
      tsJobTrav.JobTravParam[0].AgentID = "SystemAgent";
      tsJobTrav.JobTravParam[0].ReportStyleNum = 1003;    /// The MO Style
      tsJobTrav.JobTravParam[0].WorkstationID = strWkst;
      tsJobTrav.JobTravParam[0].SSRSRenderFormat = "PDF";
      tsJobTrav.JobTravParam[0].RowMod = "A";
      
      tsJobTrav.JobTravParam[0].RptPageSettings = "Color=False,Landscape=False,Margins=[Left=25 Right=25 Top=25 Bottom=25],PaperSize=[Kind=" + dquote + "Letter" + dquote + " PaperName=" + dquote + "Letter" + dquote + " Height=1100 Width=850],PaperSource=[SourceName=" + dquote + "Automatic Selection" + dquote + " Kind=" + dquote + "AutomaticFeed" + dquote + "],PrinterResolution=[Kind=" + dquote  + "Custom" + dquote + " X=600 Y=600]";
      //
      //  For each Job submitted, print twice - 1) MO single copy,  2) Traveler multiple copies
      //
      foreach(string job in jobArray)
      { 
          tsJobTrav.JobTravParam[0].Jobs = job;
          //
          //  Print command 1 (MO one copy)
          //
          tsJobTrav.JobTravParam[0].ReportStyleNum = 1003; 
          tsJobTrav.JobTravParam[0].RptPrinterSettings = "PrinterName=\"" + inPrinter + "\",Copies=" + 1 + ",Collate=False,Duplex=Simplex,FromPage=1,ToPage=0";
          svcJobTrav.SubmitToAgent(tsJobTrav, "SystemTaskAgent", 0, 0, "Erp.UIRpt.JobTrav");
          System.Threading.Thread.Sleep(4000);
          //
          //  Print command 2 (Traveler JUST ONCE, since the PDF already generates with the appropriate num copies)
          //
          tsJobTrav.JobTravParam[0].ReportStyleNum = 1002; 
          tsJobTrav.JobTravParam[0].RptPrinterSettings = "PrinterName=\"" + inPrinter + "\",Copies=" + 1 + ",Collate=False,Duplex=Simplex,FromPage=1,ToPage=0";
          svcJobTrav.SubmitToAgent(tsJobTrav, "SystemTaskAgent", 0, 0, "Erp.UIRpt.JobTrav");
          output += (output != null?"~":"") + job + ",1";  
          System.Threading.Thread.Sleep(4000);
      }
    }
    svcJobTrav.Dispose();
}

Hey Doug. Thanks for the response. Unfortunately, there is no additional text beyond what is in the image…

You have baqRptDS.BAQReportParam[0].PrinterName = “Prt57@edgeagent”;
looks like incorrect name, replace it with printer ID maybe?

Or just remove it completely because there is code to use printer settings in case when printer name is not in parameters

1 Like

Thanks Olga. That’s just a leftover from my multiple attempts at providing an acceptable printer name.

However, now that I know it’s not required, I will remove it.

So, let me first say that I am not a fan of the Edge Agent.
I decided to check on the printer’s connectivity to the Edge Agent server machine we’ve set up. The darned printer has not been responding on the Edge Agent server. I don’t know why or for how long.

I changed my “inPrinter” (BPM’s printer name variable) to another registered edge-agent printer that DOES return a successful test result via Printer Maintenance. I sent my BAQ document, and BOOM!.

Just wow! That error message from System Monitor had me searching everywhere but the proper place!!!

Thanks for the responses, all. As always, it is much appreciated.

1 Like

So you fixed printer name? That is why you stopped receiveing that error.

I changed the printer ID to a printer that I could verify as functional. I used the same format, but now referencing a different printer…

string inPrinter = $"PRT - 123 ISDEPT Color@Print-SRV-EdgeAgent";

Our naming convention needs to be tightened up, but this is a different printer AND a different edge agent server. I verified that this printer responds to the Printer maintenance “Test Printer” function and then retried my BPM print.

So, I believe the submission of the print job was always fine. However, the system monitor was reporting that the doc couldn’t be sent to the specified printer. Unfortunately, the error said the printer wasn’t properly specified, when in fact, the printer was not responding.

1 Like