How to Call a BAQ from Script Editor in Epicor ERP

Home  /  Solutions and Services  /  Epicor and ERP  /  How to Call a BAQ from Script Editor in Epicor ERP

ERP tech help

Call a BAQ from Script Editor

For this Epicor tutorial, I wanted to share a tip I have learned while working with a Business Activity Query(BAQ) in Epicor. How to call a BAQ from Script Editor.

After a BAQ has been created, you can then call the BAQ from code within the script editor inside of a customization, which allows you to access the data the BAQ returns.


Step 1.

Assuming you are familiar with creating a customization, click on the “Script Editor” tab in your customization.

The first thing you must do is add in the necessary assemblies for calling a BAQ. In the menu bar of the customization screen, select “Tools” and then “Assembly Reference Manager” to open a new window. In the lower, right-hand corner of the window, click on the “Add Custom Reference” button.

Step 2.

Select the following DLL files and click on the “Open” button.

Epicor.Mfg.AD.DynamicQuery

Epicor.Mfg.BO.DynamicQuery

Epicor.Mfg.Core.BLConnectionPool

Epicor.Mfg.IF.IDynamicQuery

Step 3.

You will now see your newly added assemblies under the “Custom Assemblies” folder.

After you have closed the window, be sure to add the following using statement to the top of your code:

using Epicor.Mfg.Lib;

Step 4.

Next, you will need to create a “session” variable inside the Script class:

// Add Custom Module Level Variables Here **

Epicor.Mfg.Core.Session session;

Inside the “InitializeCustomCode” method, initialize the session variable using the current form you are customizing:

public void InitializeCustomCode()

{

// End Wizard Added Custom Method Calls

session = (Epicor.Mfg.Core.Session)CustShipForm.Session;

}

Step 5.

Last, in the method where you want to call the BAQ, initialize the “QueryDesignDataSet” and “DynamicQuery” objects, followed by the actual call.

You can pass query parameters in as well.

private void ShipHead_AfterFieldChange(object sender, DataColumnChangeEventArgs args)

{

// Initialize objects

QueryDesignDataSet dataset = new QueryDesignDataSet();

DynamicQuery query = new DynamicQuery(session.ConnectionPool);

// Point the dataset to the BAQ

dataset = query.GetByID(string.Format("{0}-BAQName", session.CompanyID))

// Pass in a parameter

dataset.QueryWhereItem[0].RValue = 123;

// Execute the BAQ

DataTable table = query.Execute(dataset).Tables["Results"];

}

Step 6.

The data is returned in a DataTable to make it easy for you to access.

Suggested

19 Comments so far:

  1. Adan Lopez says:

    How I can get this method:

    Epicor.Mfg.BO.DynamicQuery
    ExecuteDashBoardQuery

  2. Adan Lopez says:

    Yes, this method run when I press Refresh button in a Dashboard, but I want call him with other button or when I press Enter in EpiTextBox.

    Thanks.

  3. Adan Lopez says:

    How can I do it?

  4. Jerry says:

    Hi, just wanted to let you know you missed add Epicor.Mfg.Core.Session.dll at Custom Assembly Reference Manager Thanks!

  5. I’m getting error using “QueryDesignDataSet” and “DynamicQuery”. Type or namespace name “xxx” could not be found…

  6. Rob Cowper says:

    For this kind of thing I find one typically needs to include:

    using Epicor.Mfg.Core;

    …plus assembly references to:

    Epicor.Mfg.AD.DynamicQuery
    Epicor.Mfg.BO.DynamicQuery
    Epicor.Mfg.IF.DynamicQuery
    Epicor.Mfg.Lib.ISessionMod
    Epicor.Mfg.Lib.SessionMod

  7. Molly James says:

    Thanks Rob, for your input.

  8. Adan Lopez says:

    I use dashboards-Assembly, to run my query. I press the refresh icon and want to do this using a button or pressing the Tab key,but I can’t do it.

  9. jasmjasm says:

    Hi all!! Can i do that in Epicor 10??? Thaks for your reply!!

  10. Axel says:

    Hi,

    the connection, doesn’t need a Dispose() or Close()?

  11. Naveen kumaar says:

    Can you tell me .i want to use sql connection inside the script editor,i don’t want to use BAQ .please reply me ASAP

    • Bryan Sapot says:

      There is no way to call SQL directly in the script editor. Can you explain a little more about what you are trying to do? There could be another way.

  12. Mahesh says:

    I am able to pass parameter to BAQ, But I want to something more.
    Because I have added parameter & want to use it with IN clause.
    So, Can anyone help me for how to pass ‘Parameter List’ & use it in External BAQ.

    Thanks in Advance..
    Mahesh

  13. JoeM says:

    Hello,

    I used this example to create a form customization 9.05.702A and it worked flawlessly. I am trying to build this same customization in 10.1 as a test and I’m coming across some Type or NameSpace errors:

    Error: CS0246 – line 45 (492) – The type or namespace name ‘DynamicQuery’ could not be found (are you missing a using directive or an assembly reference?)
    Error: CS0246 – line 45 (492) – The type or namespace name ‘DynamicQuery’ could not be found (are you missing a using directive or an assembly reference?)
    Error: CS0246 – line 45 (492) – The type or namespace name ‘Session’ could not be found (are you missing a using directive or an assembly reference?)
    Error: CS0246 – line 50 (497) – The type or namespace name ‘Session’ could not be found (are you missing a using directive or an assembly reference?)

    I know a lot has changed with the ICE upgrade and I am trying to learn how do deal with changes:

    In 10.1 I am referencing these Custom Assemblies:

    Ice,Contracts.BO.DynamicQuery
    Ice.Core.Session

    Any help is appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *