Printing SalesOrderAcknowledgement via ButtonClick

Does anyone have a simplified example of printing a ‘standard’ report through code, in 10.2?
I have a ButtonClick customization that launched a report in E9, but the code conversion to E10 has rendered it non-functional. The ‘usings’ have all changed to Ice (appropriately, it seems), although a trace of the manual report execution reveal calls to Erp.Proxy.Rpt.

Anything identifying the proper using directives or references and perhaps the objects to be instantiated would be appreciated. Guessing just isn’t producing results for me.

Does this get you close?

1 Like

I think it does Ken,
I’m hoping this isn’t strictly for SSRS, as we’ve opted to migrate to 10.2 (from 9) retaining our Crystal Reports. Redesigning reports is a project for another day.

Stay tuned… trying this now.

Aaargh!

So it appears “Ice” doesn’t contain “Assemblies”?

I should have asked where are you calling this? Which form? That might have been a good start. lol

Think you need to add the assemblies.

Here is a customization example on a dashboard. Another report but same concept.

Add Assemblies. You will need the SalesOrderAck one not the SOPickList

Code:

	//Invoke the BO
		SOPickListReportAdapter pl = new SOPickListReportAdapter(oTrans);
		pl.BOConnect();
		//Get Paramters
		pl.GetNewParameters();
		
		//Set Parameters
		pl.ReportData.SOPickListReportParam[0].FromDate = DateTime.Now.AddYears(-1);
		pl.ReportData.SOPickListReportParam[0].ToDate = DateTime.Now.AddYears(20);
		pl.ReportData.SOPickListReportParam[0].OrderList = sb.ToString();
		pl.ReportData.SOPickListReportParam[0].NewPage = true;
		pl.ReportData.SOPickListReportParam[0].BarCodes = false;
		pl.ReportData.SOPickListReportParam[0].PrintKitComponents = true;
		pl.ReportData.SOPickListReportParam[0].ReportStyleNum = 1001;
	pl.ReportData.SOPickListReportParam[0].AutoAction = "SSRSCLIENTPRINT";
		pl.ReportData.SOPickListReportParam[0].SSRSRenderFormat = "PDF";
		pl.ReportData.SOPickListReportParam[0].AgentID= "SystemTaskAgent";
		pl.ReportData.SOPickListReportParam[0].WorkstationID = Ice.Lib.Report.EpiReportFunctions.GetWorkStationID((Ice.Core.Session)oTrans.Session);
		
		//Submit to Agent
		pl.SubmitToAgent("SystemTaskAgent",0,0);
		MessageBox.Show("Print Job Has been submitted.");
2 Likes

Hmmm. I seem to be hitting the same brick wall, but from different angles. Can’t seem to get the correct objects instantiated, and I’m not aware of any documentation that lays out what is connected to what…

Try adding this line to the top of the script

using Erp.Adapters;

2 Likes

Yeah, I thought of that, Ken. I’ve tried adding all sorts of references and using statements to no avail. Given the few clear success stories online, it appears that printing programmatically has gotten a bit more difficult with E10. I do really appreciate your taking the time to help…

try to declare the field like note the lower case s.

salesOrderAckAdapter p2 = new salesOrderAckAdapter(oTrans);
1 Like

The way I did it for the Pick list report was to call via a new Context menu, a customization of SoPickListReport window, passing along the active sales order number. Launch the print then close the window.

Here is the generation of the report info:
try

      {
          Erp.Proxy.Rpt.SOPickListReportImpl report = WCFServiceSupport.CreateImpl<Erp.Proxy.Rpt.SOPickListReportImpl>((Ice.Core.Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Erp.Contracts.SOPickListReportSvcContract>.UriPath);

          var ds = report.GetNewParameters();
          report.GetDefaults(ds);

  		ds.SOPickListReportParam[0].ToDate = (DateTime)edvReportParam.dataView[0]["ToDate"];   	
  		ds.SOPickListReportParam[0].FromDate = (DateTime)edvReportParam.dataView[0]["FromDate"]; 

          ds.SOPickListReportParam[0].OrderList = order;
  		ds.SOPickListReportParam[0].ArchiveCode = 0;
  		ds.SOPickListReportParam[0].AgentID = "SystemTaskAgent";
  		
          ds.SOPickListReportParam[0].AutoAction = "SSRSPREVIEW";
          ds.SOPickListReportParam[0].SSRSRenderFormat = "PDF";
  		ds.SOPickListReportParam[0].WorkstationID = WorkID;
  		ds.SOPickListReportParam[0].ReportStyleNum = 1001;
  		ds.SOPickListReportParam[0].DateFormat = "mm/dd/yyyy";
  	    ds.SOPickListReportParam[0].NumericFormat = ",.";
  		ds.SOPickListReportParam[0].TaskNote = "From menu context of Sales Order: " + ds.SOPickListReportParam[0].OrderList + " by " + UserName ;
  		ds.SOPickListReportParam[0].ReportCultureCode = "en-CA";
  		if(bKitComponents)
  			ds.SOPickListReportParam[0].PrintKitComponents = true;
  		else
  			ds.SOPickListReportParam[0].PrintKitComponents = false;
  		string dquote = "\""; string dbakslash = @"\\"; string bakslash = "\\";

  		ds.SOPickListReportParam[0].RptPageSettings = "Color=True,Landscape=True,Margins=[Left=25 Right=25 Top=25 Bottom=25],PaperSize=[Kind=" + dquote + "Letter" + dquote + " PaperName=" + dquote + "Lettre" + dquote + " Height=1100 Width=850],PaperSource=[SourceName=" + dquote + "Sélection automatique" + dquote + " Kind=" + dquote + "AutomaticFeed" + dquote + "],PrinterResolution=[Kind=" + dquote  + "Custom" + dquote + " X=600 Y=600]";
  		
  		
  		string info = "";
  	
  		report.SubmitToAgent(ds, "SystemTaskAgent", ds.SOPickListReportParam[0].AgentSchedNum, 0, "Epicor.Mfg.UIRpt.SOPickListReport");
      }
      catch (Exception ex)
      {
          MessageBox.Show(ex.ToString());
      }

Hope it helps…

Pierre

2 Likes

@Hogardy, This WILL help, as the picker is next on the list. It’s interesting that the construct you’re using is different than what I’m attempting now with the SalesOrderAcknowledgement. This appears to be using some ‘other’ programming assemblage in order to create the report ‘object’? Is this the approach going forward?

@knash, you nailed it with the lowercase “s”. I’m elated and frustrated at the same time as everything that Epicor automatically inserts into the script capitalizes that first character! Even the name of the DLL is capitalized! There’s just no rhyme or reason.

Whew! Done venting. I will now work backwards to remove all the references and other test code I’ve littered the script with as I tried and errored.

I truly appreciate your help, gents.

It is lower case in the dll. Sucks that you have to take a peek at the code to find that out.

You can also use the code that I posted above along with @Hogardy for the SOPickList.

It is WCF vs. Adapter…

1 Like

Thanks again. I’ll get up to speed on this eventually, but I definitely needed the leg-up this time. On a tight deadline and have to get these reports running for go-live at the end of the month. I’m sure glad this forum is around!

I’ve not printed a report from code before, so seeing this thread I gave it a go myself using code supplied above with a bit of tweaking:

private void btnPrintSOA_Click(object sender, System.EventArgs args)
{
	//Invoke the BO
	salesOrderAckAdapter soa = new salesOrderAckAdapter(oTrans);
	soa.BOConnect();

	//Get Paramters
	soa.GetNewParameters();
	
	//Set Parameters
	soa.ReportData.SalesOrderAckParam[0].OrderNum = 123770;
	soa.ReportData.SalesOrderAckParam[0].AutoAction = "PREVIEW";
	soa.ReportData.SalesOrderAckParam[0].AgentID = "SystemTaskAgent";
	soa.ReportData.SalesOrderAckParam[0].ReportStyleNum = 1003;
	soa.ReportData.SalesOrderAckParam[0].WorkstationID = Ice.Lib.Report.EpiReportFunctions.GetWorkStationID((Ice.Core.Session)oTrans.Session);
	soa.ReportData.SalesOrderAckParam[0].ArchiveCode = 7;

	//Submit to Agent
	soa.SubmitToAgent("SystemTaskAgent",0,0);
	MessageBox.Show("Print Job Has been submitted.");

	
}

Works a charm - only needed to add reference for the Erp.UIRpt.SalesOrderAck.

2 Likes

Yep, once you know what you’re doing, it ain’t so bad :wink:
I wonder if that reference is documented anywhere - or did someone figure it out by trial and error.

In any case, I think the comments on this thread will be useful to others - it certainly was for me.

1 Like

Is there any way to do this with a custom BAQ report?

The code below gets the printer settings from a BAQ I wrote that links user names to printers in the system and then submits the BAQ report to the System Agent.

private void PrintBillsSSRS(){
		if (numBOLNum.Value == null || Convert.ToInt32(numBOLNum.Value) <= 0) { return; }
		// Make sure the boxes and weight are up-to-date before printing
		UpdateBOLBoxesAndWeight(Convert.ToInt32(numBOLNum.Value));
	    // ** Place Event Handling Code Here **
		string[] printerInfo = GetDefaultPrinter(((Session)HHConfirmShipForm.Session).UserID);
	    string printer = printerInfo[0];
		string pageSettings = printerInfo[1];
		string printerSettings = printerInfo[2];
		//MessageBox.Show("Printer: " + printer);
	    string agentID = "";
	
	    try
	    {
	        Session otSession = (Session)oTrans.Session;
	
	        //Set the workstationID
	        string workStation = Ice.Lib.Report.EpiReportFunctions.GetWorkStationID(otSession);
	
	        //Get or Set the AgentID
	        using (var aSA = new SysAgentAdapter(oTrans))
	        {
	            //oTrans.PushStatusText("Get System Agent Info", true);
	            aSA.BOConnect();
	            aSA.GetDefaultTaskAgentID(out agentID);
	            if (!string.IsNullOrEmpty(agentID)) { agentID = "SystemTaskAgent"; }
	        }
	
	        //MessageBox.Show(agentID + ", " + workStation);
			for (int i =0; i < 3; i++)
	        {
	            var baqR = WCFServiceSupport.CreateImpl<Ice.Proxy.Rpt.BAQReportImpl>((Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.BAQReportSvcContract>.UriPath);
	            var dynamicReport = WCFServiceSupport.CreateImpl<Ice.Proxy.BO.DynamicReportImpl>((Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.DynamicReportSvcContract>.UriPath);
	            var rptMonitor = WCFServiceSupport.CreateImpl<Ice.Proxy.BO.ReportMonitorImpl>((Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.ReportMonitorSvcContract>.UriPath);
	
	            // GET DEFAULT REPORT PARAMETERS
	            var rptDs = dynamicReport.GetByID("PSG-tmsCustBOL");
	            var baqRptDS = baqR.GetNewBAQReportParam("PSG-tmsCustBOL");
	            baqRptDS.BAQReportParam[0].Option01 = numBOLNum.Value.ToString();
	            baqRptDS.BAQReportParam[0].AutoAction = "SSRSPRINT";
	            baqRptDS.BAQReportParam[0].WorkstationID = workStation;
				baqRptDS.BAQReportParam[0].PrinterName = printer;
				baqRptDS.BAQReportParam[0].RptPageSettings = pageSettings;
				baqRptDS.BAQReportParam[0].RptPrinterSettings = printerSettings;
	            baqRptDS.BAQReportParam[0].SSRSRenderFormat = "PDF";
	            //baqRptDS.BAQReportParam[0].Character01 = numBOLNum.Value.ToString();
	            //baqRptDS.BAQReportParam[0].Character02=flag;
	            baqRptDS.BAQReportParam[0].BAQRptID = "PSG-tmsCustBOL";
	            baqRptDS.BAQReportParam[0].ReportID = "PSG-tmsCustBOL";
	            baqRptDS.BAQReportParam[0].Summary = false;
	            baqRptDS.BAQReportParam[0].ReportStyleNum = 1;
	            baqRptDS.BAQReportParam[0].BAQID = "PSG-tmsCustomerBOL";
	            baqRptDS.BAQReportParam[0].ReportTitle = "Bill of Lading";
	            //baqRptDS.BAQReportParam[0].TaskNote = guid.ToString();
	            rptDs.BAQRptOptionFld[0].FieldValue = numBOLNum.Value.ToString();
	
	            rptDs.AcceptChanges();
	            StringWriter writer = new StringWriter();
	            rptDs.WriteXml(writer);
	            baqRptDS.BAQReportParam[0].Filter1 = writer.ToString();
	
	            //baqR.RunDirect(baqRptDS);
	            baqR.SubmitToAgent(baqRptDS, agentID, 0, 0, "Erp.UIRpt.BAQReport");
	
	            //MessageBox.Show("Report Submitted to System Agent for processing.");
	        }
	    }
	    catch (Exception ex)
	    {
	        MessageBox.Show("An error occured trying to print report." + ex.Message);
	    }
	}
	
	// Gets the printer for the current user.
	private string[] GetDefaultPrinter(string currentUser)
	{
		string[] output = new string[3];
		string printer = string.Empty;
		string pageSet = "Color=True,Landscape=False,PaperSize=[Kind=\"Letter\" PaperName=\"Letter\" Height=1100 Width=850],PaperSource=[SourceName=\"FormSource\" Kind=\"FormSource\"],PrinterResolution=[Kind=\"Custom\" X=600 Y=600]";
		string printSet = "PrinterName=\"" + printer + "\",Copies=1,Collate=False,Duplex=Default,FromPage=1,ToPage=0";
		// Special cases for PLT02 and PLT03, because we can only add 2 printers to each workstationID
		if (currentUser.ToUpper().Equals("HH10") || currentUser.ToUpper().Equals("HH04"))
		{
			// PLT02. Default to PLT2-PR-02
			printer = "\\\\PSG-SRV-02\\PLT2-PR-02";
			printSet = "PrinterName=\"" + printer + "\",Copies=1,Collate=False,Duplex=Default,FromPage=1,ToPage=0";
			output[0] = printer;
			output[1] = pageSet;
			output[2] = printSet;
			return output;
		} else if (currentUser.ToUpper().Equals("HH08") || currentUser.ToUpper().Equals("HH05") || currentUser.ToUpper().Equals("HH06"))
		{
			// PLT03. Default to PLT3-PR-06
			printer = "\\\\PSG-SRV-02\\PLT3-PR-06";
			printSet = "PrinterName=\"" + printer + "\",Copies=1,Collate=False,Duplex=Default,FromPage=1,ToPage=0";
			output[0] = printer;
			output[1] = pageSet;
			output[2] = printSet;
			return output;
		}
		DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
		dqa.BOConnect();
		QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("PSG_tmsPrinterForUser");
		qeds.ExecutionParameter.Clear();
		qeds.ExecutionParameter.AddExecutionParameterRow("UserID", currentUser, "nvarchar",false,Guid.NewGuid(), "A");
		dqa.ExecuteByID("PSG_tmsPrinterForUser", qeds);
		foreach (DataRow row in dqa.QueryResults.Tables["Results"].Rows)
		{
			// Only use printers that aren't label printers (do not contain "LBL")
			if (!row["SysPrinter_PrinterID"].ToString().ToUpper().Contains("LBL"))
			{
				printer = row["SysPrinter_NetworkPath"].ToString();
				pageSet = row["Calculated_PageSettings"].ToString();
				printSet = row["Calculated_PrinterSettings"].ToString();
			}
		}
		output[0] = printer;
		output[1] = pageSet;
		output[2] = printSet;
		return output;
	}
4 Likes

What assembly do I need to include to get the string printerInfo = GetDefaultPrinter(((Session)HHConfirmShipForm.Session).UserID);

the printer information? using Get Default Printer to work?