# Calling a BAQ report

**URL:** <https://www.epiusers.help/t/calling-a-baq-report/81460>\
**Category:** Epicor ERP 10\
**Tags:** e10\
**Created:** [August 10, 2021, 12:15pm UTC](https://www.epiusers.help/t/calling-a-baq-report/81460 "2021-08-10T12:15:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joel\_Bailie](https://www.epiusers.help/letter_avatar_proxy/v4/letter/j/c37758/32.png) [@Joel\_Bailie](https://www.epiusers.help/u/Joel_Bailie)\
**Post date:** [August 10, 2021, 12:15pm UTC](https://www.epiusers.help/t/calling-a-baq-report/81460/1 "2021-08-10T12:15:54Z")

</div>

I am still relatively new to Epicor and very new to this type of endeavor. I am trying to run/call a BAQ Report from a button click and am not sure how to accomplish this in my customization

My Report ID is SerialNumberLab  
BAQ ID is BAQR\_SerialNumbers

This is the code I have thus far inside my button click handler.

Ice.UI.Rpt.BAQReport.Transaction trans = new Ice.UI.Rpt.BAQReport.Transaction(oTrans);

trans.LoadBAQReportData(“SerialNumberLab”);

EpiDataView edvData = (EpiDataView)trans.EpiDataViews[“ReportParams”];  
string strCarton = edvData.dataView[edvData.Row][“Carton”].ToString();  
string strPart = edvData.dataView[edvData.Row][“Part”].ToString();

trans.RunDirect(“Preview”);

edvData.Dispose();  
trans.Dispose();

It isn’t working as desired though. Have any of you guys ever tried to do this or do any of you see what I have done wrong?

---

<div class="post-metadata">

**Author:** ![knash](https://www.epiusers.help/user_avatar/www.epiusers.help/knash/32/74179_2.png) [@knash](https://www.epiusers.help/u/knash)\
**Post date:** [August 10, 2021, 12:43pm UTC](https://www.epiusers.help/t/calling-a-baq-report/81460/2 "2021-08-10T12:43:03Z")

</div>

Here is how we do it. There is a bit more here then just calling the report. You also need to set printer settings, which can be seen from the trace when calling the BAQ Report from the menu. (I am assuming that is how folks call it today)

```
private void printReport()
	{
	    // **Place Event Handling Code Here**
		string[] printerInfo = GetDefaultPrinter(((Session)oTrans.Session).UserID);
	    string printer = printerInfo[0];
		string pageSettings = printerInfo[1];
		string printerSettings = printerInfo[2];
	    string agentID = "";
		string strSerialNum = edvSerialNumDV.dataView[edvSerialNumDV.Row]["SerialNumber"].ToString();
	
	    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))
	        {
	            aSA.BOConnect();
	            aSA.GetDefaultTaskAgentID(out agentID);
	            if (!string.IsNullOrEmpty(agentID)) { agentID = "SystemTaskAgent"; }
	        }
	
			for (int i =0; i < 1; 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);
	
	            // GET DEFAULT REPORT PARAMETERS
	            var rptDs = dynamicReport.GetByID("ETK_RMA_Trav");
	            var baqRptDS = baqR.GetNewBAQReportParam("ETK_RMA_Trav");
	            baqRptDS.BAQReportParam[0].Option01 = strSerialNum;
	            baqRptDS.BAQReportParam[0].AutoAction = "SSRSClientPrint";
	            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].BAQRptID = "ETK_RMA_Trav";
	            baqRptDS.BAQReportParam[0].ReportID = "ETK_RMA_Trav";
	            baqRptDS.BAQReportParam[0].Summary = false;
	            baqRptDS.BAQReportParam[0].ReportStyleNum = 1;
	            baqRptDS.BAQReportParam[0].BAQID = "ETK_RMA_Trav";
	            baqRptDS.BAQReportParam[0].ReportTitle = "Depot RMA Traveller";
	            rptDs.BAQRptOptionFld[0].FieldValue = strSerialNum;
	
	            rptDs.AcceptChanges();
	            StringWriter writer = new StringWriter();
	            rptDs.WriteXml(writer);
	            baqRptDS.BAQReportParam[0].Filter1 = writer.ToString();
	            baqR.SubmitToAgent(baqRptDS, agentID, 0, 0, "Erp.UIRpt.BAQReport");
	        }
	    }
	    catch (Exception ex)
	    {
	        MessageBox.Show("An error occured trying to print report." + ex.Message);
	    }
	}
```

---

<div class="post-metadata">

**Author:** ![Joel\_Bailie](https://www.epiusers.help/letter_avatar_proxy/v4/letter/j/c37758/32.png) [@Joel\_Bailie](https://www.epiusers.help/u/Joel_Bailie)\
**Post date:** [August 10, 2021, 12:56pm UTC](https://www.epiusers.help/t/calling-a-baq-report/81460/3 "2021-08-10T12:56:58Z")

</div>

Thank you sir. I will look at this.
