Epicor: How To Call A BAQ Report From Within A Customization

We have already documented how you can call a BAQ from within a customization on this article but what if you want to run a BAQ Report? While there is more than one way, I find the most efficient methodology is to simply launch the BAQ Report dialog, auto-populate the fields to run the report, and execute the event to either print or preview the report. And we can do that without the user having any clue to the complexity behind the scenes by using scenario #3 from this guide. If you follow that guide and reference Ice.UIRpt.BAQReport then you can use a code snippet like this to easily print or preview any BAQ Report that you like:

// Establish your reference to the BAQ Report UI
Ice.UI.Rpt.BAQReport.Transaction trans = new Ice.UI.Rpt.BAQReport.Transaction(oTrans);

// Load the specific BAQ Report by ID you are interested in
trans.LoadBAQReportData("MyBAQReport");

// Fill in the parameters to run the report.  You can find these
// by using field help on the BAQ Report dialog.
EpiDataView edvData = (EpiDataView)trans.EpiDataViews["ReportParam"];
edvData.dataView[edvData.Row]["field1"] = "PART123";
edvData.dataView[edvData.Row]["field2"] = "CUSTOMERXYZ";

// Submit to system agent.  You can do either a preview or print here
trans.RunDirect("Preview");

// Clean up the objects
edvData.Dispose();
trans.Dispose();

That is all there is to it!