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