5/16/24, 3:51 PM Epicor: Call a BAQ From Code Customization — GingerHelp
support@gingerhelp.com
E P I C O R : H OW TO CA L L A
B AQ F R O M C O D E W I T H I N A
C U STO M I Z AT I O N
ADAM ELLIS · DECEMBER 12, 2019
BAQs are such a fantastic building block for so many things within Epicor.
You have probably used them to build dashboards and quick searches,
but in this article, I wanted to describe how you can run them via code
within an embedded customization. I use this technique all of the time -
most recently, I had a customer that wanted to have a selectable grid of
shipment notification recipients listed at order entry formed by pulling
together all of the customer contacts having a specific set of criteria.
While I might have been able to get creative with foreign key views to pull
that together, a simple BAQ gets the job done clean and fast.
As you might imagine, the process here is going to start by creating a
BAQ. There are no special rules here - you can use any type of BAQ,
including those that have parameters.
https://www.gingerhelp.com/knowledgebase-epicor-erp/executing-a-baq-from-code-within-a-customization 1/11
5/16/24, 3:51 PM Epicor: Call a BAQ From Code Customization — GingerHelp
Here is a BAQ that has a parameter prompting for the CustNum.
In order to use this BAQ within a customization we need to first add an
assembly reference using Tools / Assembly Reference Manager:
From here click the ‘Custom Assemblies’ folder and then press the ‘Add
https://www.gingerhelp.com/knowledgebase-epicor-erp/executing-a-baq-from-code-within-a-customization 2/11
5/16/24, 3:51 PM Epicor: Call a BAQ From Code Customization — GingerHelp
Custom Reference’ button:
Now change the type drop-down to all and select the DLL file
Ice.Contracts.BO.DynamicQuery.DLL (be careful to pick the DLL and not
the XML file with the same name):
https://www.gingerhelp.com/knowledgebase-epicor-erp/executing-a-baq-from-code-within-a-customization 3/11
5/16/24, 3:51 PM Epicor: Call a BAQ From Code Customization — GingerHelp
Now we are ready to add our code. We start off with some boilerplate
stuff:
https://www.gingerhelp.com/knowledgebase-epicor-erp/executing-a-baq-from-code-within-a-customization 4/11
5/16/24, 3:51 PM Epicor: Call a BAQ From Code Customization — GingerHelp
Breaking those down just a bit:
• The first line we are creating an object called dynamicQueryAdapter
of the type DynamicQueryAdapter at the script level - this means we
will be able to use it anywhere within the customization.
• The second two lines are nested within the InitializeCustomCode
function and this is where we are actually wiring up
dynamicQueryAdapter to actually work. Note that on the line that
says:
dynamicQueryAdapter = new DynamicQueryAdapter(UD01Form);
The bit in the parenthesis needs to be the name of the form as obtained
from the top of the tree view:
https://www.gingerhelp.com/knowledgebase-epicor-erp/executing-a-baq-from-code-within-a-customization 5/11
5/16/24, 3:51 PM Epicor: Call a BAQ From Code Customization — GingerHelp
• The last line is just disposing the dynamicQueryAdapter object so
we don’t end up with a memory leak.
Now that we have the basics in place we are ready to actually call out to
our BAQ. Ultimately it is going to depend on your use case exactly where
you wedge this next bit of code. For my customer that was wanting to
pull in shipment notification recipients we attached this to the
EpiViewNotification for OrderHed. For the purpose of this article I am just
attaching the code to the form load event:
private void UD01Form_Load(object sender, EventArgs ar
{
int myCustNum = 414;
QueryExecutionDataSet queryExecutionDataSet = new
queryExecutionDataSet.Tables["ExecutionParameter"]
.Add("CustNum", myCustNum, "int", false, null,
dynamicQueryAdapter.ExecuteByID("CustomerContacts"
epiUltraGridC1.DataSource = dynamicQueryAdapter.Qu
}
https://www.gingerhelp.com/knowledgebase-epicor-erp/executing-a-baq-from-code-within-a-customization 6/11
5/16/24, 3:51 PM Epicor: Call a BAQ From Code Customization — GingerHelp
Breaking this down a bit:
• We start with setting a variable for a static customer number we will
later use to fill in the parameter on our BAQ:
int myCustNum = 414;
• Next we initialize a new QueryExecutionDataSet - an object that
holds things like parameters for our BAQ:
QueryExecutionDataSet queryExecutionDataSet = new Quer
• Now if you have any parameters you are going to use this next line
paying special attention to those first three arguments after Add -
they refer to the name of the parameter, the value you want to pass
in, and the type of parameter. You will repeat this line for each
parameter your BAQ calls for:
queryExecutionDataSet.Tables["ExecutionParameter"].Row
• Now we execute our BAQ using ExecuteByID. The first parameter is
the name of our BAQ and the second is the queryExecutionDataSet
we just created:
dynamicQueryAdapter.ExecuteByID("CustomerContacts", qu
• At this point the results of the BAQ will be stored at
dynamicQueryAdapter.QueryResults.Tables["Results"]. You can do
whatever you want with them at this point including binding them to
controls or even creating brand new EpiDataViews.
Hope this has been helpful!
https://www.gingerhelp.com/knowledgebase-epicor-erp/executing-a-baq-from-code-within-a-customization 7/11
5/16/24, 3:51 PM Epicor: Call a BAQ From Code Customization — GingerHelp
LET'S CHAT ABOUT YOUR NEXT EPICOR
BAQ PROJECT!
AUTHOR: Adam Ellis
Adam Ellis is the owner of
GingerHelp. Adam is a lifelong
entrepreneur and has extensive ERP
and mobile software knowledge
through his consulting and
management experience. He has a
passion for exploring innovative ideas
and how they can change the status
quo. Connect with Adam on LinkedIn
to learn more about his involvement
in the ERP space.
FACEBOOK TWI TTER PINTEREST 0 LIKES
COMMENTS (3) Newest First
Preview POST COMMENT…
https://www.gingerhelp.com/knowledgebase-epicor-erp/executing-a-baq-from-code-within-a-customization 8/11
5/16/24, 3:51 PM Epicor: Call a BAQ From Code Customization — GingerHelp
Dan A year ago · 0 Likes
And how do you do if it's a BAQ Update. How do I pass the updated value? Thanks.
vb 2 years ago · 0 Likes
Hi,
Can you show me the process to add a print menu in Any form Actions?
using process calling.
Regards
Joel Ray Bailie 3 years ago · 0 Likes
Great article Adam. It helped me get a BAQ result into a grid on my form.
PREVIOUS
ACCESSING / UPDATING FIELDS THE RIGHT WAY USING EPICOR
EPIVIEWS
EPICOR CUSTOMIZATION, EPICOR ERP
NEXT
SENDING HTML EMAILS FROM WITHIN AN EPICOR 10 BPM
EPICOR ERP, EPICOR BPM, EPICOR CUSTOMIZATION
LET’S CHAT!
CONTACT US
https://www.gingerhelp.com/knowledgebase-epicor-erp/executing-a-baq-from-code-within-a-customization 9/11
5/16/24, 3:51 PM Epicor: Call a BAQ From Code Customization — GingerHelp
GINGERHELP, SERVIC PRODU KNOWLEDGE
LLC ES CTS BASE
8685 Fox Epicor ERP Epicor ERP Epicor ERP Articles
Lake Road Consulting Extensions Infor VISUAL Articles
Sterling, OH P21 ERP Infor Dynamics 365
44276 USA Consulting VISUAL ERP Articles
Infor Extensions Crystal Reports
VISUAL ERP Articles
support@gingerhelp.com Consulting SSRS Articles
Dynamics Bezlio for Mobile
365 ERP Articles
Consulting
SSRS
Developer
Services
Crystal
Reports
Consulting
GingerHelp is an
independent consulting
practice with no direct
© 2019 - 2023 GingerHelp,
affiliation with Epicor® or
LLC
Infor®.
Epicor®, Vantage®, and
https://www.gingerhelp.com/knowledgebase-epicor-erp/executing-a-baq-from-code-within-a-customization 10/11
5/16/24, 3:51 PM Epicor: Call a BAQ From Code Customization — GingerHelp
Prophet 21™ are registered Terms & Conditions |
trademarks of Epicor Privacy Policy
Software Corporation®.
Infor® and VIUSAL® are
registered trademarks of
Infor®.
Crystal Reports® is a
registered trademark of SAP
AG.
https://www.gingerhelp.com/knowledgebase-epicor-erp/executing-a-baq-from-code-within-a-customization 11/11