How to Email an Epicor BAQ Report From a Customization
Last week we spelled out how you can automatically print or preview an Epicor ERP BAQ report from within customizations.
But what if you want to email an Epicor BAQ report from customizations? Unfortunately, that is a little more complex.
For this one, you will need to reference Ice.Contracts.DynamicReport and Ice.Contracts.Rpt.BAQReport and, as opposed to simply automating the calls to the UI form, we are going to use the business object directly:
// Start off by getting a reference to your current session object Ice.Core.Session session = (Ice.Core.Session)oTrans.Session; // Now we need to make a reference to DynamicReport so that we can // get a definition of what this report needs to run Ice.Proxy.BO.DynamicReportImpl dynamicReportImpl = (Ice.Proxy.BO.DynamicReportImpl)WCFServiceSupport.CreateImpl<Ice.Proxy.BO.DynamicReportImpl>(session, (string)Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.DynamicReportSvcContract>.UriPath); // Here we use GetByID to get the details to run thsi report Ice.BO.DynamicReportDataSet reportDs = dynamicReportImpl.GetByID("MyBAQReport"); // The dataset that comes back on GetByID has a table named BAQRptOptionFld // that has 1 row per input option you defined on the BAQ report. // Fill in the values here for each row. reportDs.Tables["BAQRptOptionFld"].Rows[0]["FieldValue"] = "PART123"; reportDs.Tables["BAQRptOptionFld"].Rows[1]["FieldValue"] = "CUST123"; // Take this dataset and write it out to an XML string System.IO.StringWriter writer = new System.IO.StringWriter(); reportDs.WriteXml(writer); // Now load the BAQ Report so we can submit it to the agent. // Reference the business object. Ice.Proxy.Rpt.BAQReportImpl baqReportImpl = (Ice.Proxy.Rpt.BAQReportImpl)WCFServiceSupport.CreateImpl<Ice.Proxy.Rpt.BAQReportImpl>(session, (string)Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.BAQReportSvcContract>.UriPath); // Now create a new BAQReportDataSet Ice.Rpt.BAQReportDataSet baqDS = new Ice.Rpt.BAQReportDataSet(); // Call GetNewParametersForReportId to get the parameters to run the report baqDS = baqReportImpl.GetNewParametersForReportId("MyBAQReport"); // Tell it the BAQ for this BAQ Report baqDS.Tables["BAQReportParam"].Rows[0]["BAQID"] = "MyBAQID"; // Just used for system monitor baqDS.Tables["BAQReportParam"].Rows[0]["ReportTitle"] = "My Report Title"; baqDS.Tables["BAQReportParam"].Rows[0]["Summary"] = false; // Don't get confused here, we tell it SSRSPrint but it is really going to email baqDS.Tables["BAQReportParam"].Rows[0]["AutoAction"] = "SSRSPrint"; baqDS.Tables["BAQReportParam"].Rows[0]["EMailTo"] = "aellis@gingerhelp.com"; // Email subject goes into the FaxSubject field for some reason baqDS.Tables["BAQReportParam"].Rows[0]["FaxSubject"] = "Email Subject Goes Here"; // This is that XML output from earlier baqDS.Tables["BAQReportParam"].Rows[0]["Filter1"] = writer.ToString(); baqReportImpl.SubmitToAgent(baqDS, "System Task Agent", 0, 0, "Ice.UIRpt.BAQReport");
So definitely not a simple one this week but a useful one. Imagine all of those spots now where you can have a button fire off emailed reports!