Printing from a customization
Every Epicor report form (PO Form, Job Traveler, Pack Slip…) is driven by a report adapter whose dataset holds one parameter row: the same options you’d tick on the report screen. A customization can fill that row and submit the report without the user ever opening the report form. That’s how you build buttons like “email this PO to the supplier” or “print travelers for every selected job”.
Print or email one report from a button
Section titled “Print or email one report from a button”The pattern is: create the report adapter, load its default parameters, set the fields you need, submit. NOTE: THE SPECIFIC ACTIONS USED MAY DIFFER PER VERSION.
private void SendPurchaseOrder(int poNum, string toEmail, string ccEmail){ POFormAdapter rpt = new POFormAdapter(oTrans); try { rpt.BOConnect(); rpt.GetDefaults();
var p = rpt.ReportData.POFormParam[0]; p.PONum = poNum; p.AutoAction = "SSRSPrint"; p.SSRSEnableRouting = false; p.PrintReportParameters = false; p.AttachmentType = "PDF"; p.EMailTo = toEmail; p.EMailCC = ccEmail; p.FaxSubject = "Purchase order " + poNum; p.EMailBody = "Please find purchase order " + poNum + " attached.";
rpt.RunDirect(); } finally { rpt.Dispose(); }}- The parameter row’s name and fields differ per report (
POFormParam,JobTravParam…). Open the report form in Developer Mode and look at theReportParamview’s columns, or use the Object Explorer, to see what’s there. RunDirect()runs the report straight away;SubmitToAgent(...)queues it on the task agent like the report screen’s Print button does. Queuing is kinder to the user’s screen for large reports.- Look up addresses with an adapter rather than hard-coding them, for example the buyer’s email from
PurAgentAdapter.GetByID(buyerID)or the supplier’s primary contact fromVendorAdapter. See Adapters, BAQs and searches.
Wire the method to a button or to a custom Actions menu tool, and enable that tool only when the record is in the right state (approved, has an email address); see Toolbars and tool clicks.
Batch printing reports with their attachments
Section titled “Batch printing reports with their attachments”A common shop-floor request: print the traveler for each selected job and the drawings attached to it, in order, as one stack. Epicor won’t interleave report output with attachments by itself, but a customization can orchestrate it:
- Pick the jobs. A BAQ (in an embedded grid) returns jobs ready to print, with a checkbox column.
- Submit one report per job, tagged. Generate one run ID (
Guid.NewGuid()) for the batch and put it in each report’sTaskNoteparameter, then submit each report to the task agent with the render format set to PDF and routing off. - Wait for them to finish. Poll a BAQ that counts system tasks with that note that are still active or pending. When the count reaches zero, every report is done.
- Fetch the generated PDFs. A second BAQ joins the completed tasks to their report output to return each report’s
SysRowID(and the job number from the task parameters). Download each with the report monitor adapter. - Fetch each job’s attachments and save them next to the report.
- Send the files to the printer in the order you want.
The polling query can be as small as this:
select count(*) as PendingCountfrom Ice.SysTaskwhere SysTask.TaskStatus in ('ACTIVE', 'PENDING') and SysTask.TaskNote = @RunIDDownloading a finished report is one call:
using (ReportMonitorAdapter monitor = new ReportMonitorAdapter(oTrans)){ monitor.BOConnect(); byte[] pdf = monitor.GetReportBytes(reportSysRowID); string file = System.IO.Path.Combine(System.IO.Path.GetTempPath(), reportSysRowID + ".pdf"); System.IO.File.WriteAllBytes(file, pdf);}How you download attachments depends on where they’re stored: files on a network share can be copied directly, while documents in Epicor’s content management store are downloaded through the attachment service.
Sources
This page is written in our own words. It was informed by: