C# Code to Print

I’m using the below code to print some invoices.
It works, for the most part, but I’m running into 2 snags.

  1. I have to be logged in as the user that scheduled the task (it runs using User Process Scheduler), which is annoying.

  2. I’m trying to have it go to APM, but it never makes it. When I look at the client it brings up the save window for a *.XPS file. What have I missed?

        using(var arForm = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.ARInvFormSvcContract>(Db))
     	{
     		ARInvFormTableset arTS = arForm.GetNewParameters();
     		ARInvFormParamRow r = arTS.ARInvFormParam[0];
     		r.InvoiceNum = Convert.ToInt32(result.ih.InvoiceNum);
     		r.CurGroup = "";
     		r.PrintNPost = false;
     		r.Vouchering = false;
     		r.AssignLegalNumber = false;
     		r.Description = "";
     		r.DocTypeOption = "All";
     		r.EnableAssignLegalNumber = false;
     		r.PrintStatusOption = "All";
     		r.TranDocTypeID = "";
     		r.TransOptions = "ARC";
     		r.CustList = "";
     		r.DCList = "";
     		r.TH_IsService = false;
     		r.ARInvFormReportID = "";
     		r.BeginNum = "";
     		r.EndNum = "";
     		r.InvoiceStatusOption = "A";
     		r.THHeadOfficeOrBranch = "";
     		r.THPlaceOfBusiness = "";
     		r.TWCompInvPart1 = true;
     		r.TWCompInvPart2 = false;
     		r.TWCompInvPart3Front = false;
     		r.TWCompInvPart3Back = false;
     		r.SysRowID = Guid.Empty;
     		r.AutoAction = "PRINT";
     		r.PrinterName = "Epicor APM Printer";
     		r.AgentSchedNum = 0;
     		r.AgentID = "SystemTaskAgent";
     		r.AgentTaskNum = 0;
     		r.RecurringTask = false;
     		r.RptPageSettings = "";
     		r.RptPrinterSettings = "";
     		r.RptVersion = "";
     		r.ReportStyleNum = 1015;
     		r.WorkstationID = "ISIEPICOR 2";
     		r.TaskNote = "";
     		r.ArchiveCode = 1; //7 for a week
     		r.DateFormat = @"m/d/yyyy";
     		r.NumericFormat = ",.";
     		r.AgentCompareString = "";
     		r.ProcessID = "";
     		r.ProcessCompany = "";
     		r.ProcessSystemCode = "";
     		r.ProcessTaskNum = 0;
     		r.DecimalsGeneral = 0;
     		r.DecimalsCost = 0;
     		r.DecimalsPrice = 0;
     		r.GlbDecimalsGeneral = 0;
     		r.GlbDecimalsCost = 0;
     		r.GlbDecimalsPrice = 0;
     		r.FaxSubject = "";
     		r.FaxTo = "";
     		r.FaxNumber = "";
     		r.EMailTo = "";
     		r.EMailCC = "";
     		r.EMailBCC = "";
     		r.EMailBody = "";
     		r.AttachmentType = "";
     		r.ReportCurrencyCode = result.ih.CurrencyCode.ToString();
     		r.ReportCultureCode = "en-US";
     		r.UIXml = "";
     		r.PrintReportParameters = false;
     		r.SSRSEnableRouting = false;
     		r.SSRSRenderFormat = "PDF";
     		r.RowMod = "A";
     		arForm.RunDirect(arTS);
     	}//End using
    

This is running from a BPM. Is the APM printer in the server ? BPMs run server side

Yes, the APM printer is installed on the server.

what is the logged in user’s default printer?

The workstation value is an issue. Workstation tells the server which client to execute under. Leave workstation blank and see if it helps

Jose, I tried removing the workstation, but now the reports say they complete, but do not show up on the Reports tab.

Right… I feared that… What about using auto print? Did you check out Nathan’s post about printing? In Experts Corner?