In this post, we’ll explore how to integrate a standard Business Activity Query (BAQ) into a C# application using Epicor’s .NET DLLs. This allows you to programmatically call BAQs and retrieve data within a custom application.
If you haven’t already, go check out our last episode from this series!.
1. Setting Up the Environment
Before you begin, ensure you have access to the necessary Epicor DLLs in your C# project. Typically, these include:
- Erp.BO.DynamicQuery.dll
- Erp.Contract.dll
- Ice.Proxy.Lib.dll
Add references to these DLLs in your project.
2. Creating the Connection
To interact with Epicor, you need to establish a connection to the server. Here’s an example of how to do that:
var session = new Ice.Core.Session("username", "password", "AppServerURL", Ice.Core.Session.LicenseType.Default);
3. Invoking the BAQ
Once connected, you can invoke your BAQ as follows:
csharpCopy codevar dqAdapter = new Erp.Adapters.DynamicQueryAdapter(session);
dqAdapter.BOConnect();
var baqParameters = dqAdapter.GetQueryExecutionParametersByID("YourBAQID");
dqAdapter.ExecuteByID("YourBAQID", baqParameters);
4. Handling Parameters
If your BAQ requires parameters, you can set them programmatically:
csharpCopy codevar paramRow = baqParameters.ExecutionParameter.FirstOrDefault(param => param.ParameterID == "ParameterName");
paramRow.ParameterValue = "YourValue";
5. Retrieving Results
After executing the BAQ, retrieve the results like this:
csharpCopy codevar results = dqAdapter.QueryResults.Tables["ResultsTableName"];
foreach (DataRow row in results.Rows)
{
// Process your data here
}

Conclusion
Integrating BAQs into a C# environment enhances your application’s functionality by leveraging Epicor’s robust querying capabilities. Stay tuned for more tips on optimizing your Epicor integrations. Be sure to stay tune at our news section for next episodes!.