Question: How to install or location of Ice.Lib.RESTHelper?

I need to run a BAQ from a button click in a customization. I want to do this in a Function, looking forward to converting to Kinetic screens. However I’m VERY new to using Functions, and I haven’t been able to find the Ice.Lib.RestHelper library referred to in posts here to use it in a Function. I anted to see if anyone knows how to get the library, or where it should be located. Is it the Nuget package that @josecgomez created, and if so, where would I install it so that Epicor can use it? I am under a time constraint right now, so any help available quickly would be greatly appreciated!

There is no need to use that library to run a baq from a function.

Gimme a sec, I’ll find you something or make you something.

Kevin, I apologize. I think I need to run the function from a REST call, not the BAQ. In fact I think the BAQ will be an External BAQ using a SQL stored procedure as the data source. I’ve looked at so many posts since yesterday dealing with BAQs and functions my head’s been swimming!

Ok, slow down.

Explain exactly the whole process of what you want to do, and why.

OK… I want to run an External BAQ in a function, sending a Quote number and returning a table of values to the function, which would then be updating an order’s Unit Prices with the BAQ results. The function would be called from a customization button click.

Classic or Kinetic Web?

And you don’t need help with this part correct?

This would be from a Classic version screen. I know how to set up an External BAQ, just haven’t used Functions yet, and I’m trying to create this logic to run when we start switching over to Kinetic screens. I could probably use an example on running the BAQ from the function and working with the return data if you have one…

Extremely simple example:

Here is a library. Remove the txt off the end.

JMyers56.efxj.txt (2.2 KB)

Here is the code inside:

//reference: Ice.Contracts.BO.DynamicQuery.dll
//in parameter: baqName
//out parameter: baqOutput

CallService<DynamicQuerySvcContract>( svc =>
    QueryExecutionTableset qeTS = svc.GetQueryExecutionParametersByID(baqName);   
    baqOutput = svc.ExecuteByID(baqName, qeTS);

Thanks for the example, Kevin. I tried to import it, however got an error about the version being a later one than what I have. I’m just going to copy and paste into a new function.

Kevin, was this function created using the widgets, or direct code?

This is a code function.

Calling it from client code:

//All should already be in client directory. Choose all files to see them.

using Ice.Lib.RestClient;
using Ice.Core;
using Newtonsoft.Json;
private void epiButtonC1_Click(object sender, System.EventArgs args)
    string restApiKey   = "Your APIKEY Here";
    string libraryName  = "JMyers56";
    string functionName = "CallBAQ";		
    var functionInputParameters = new RestContent(
        baqName = "aaaa"

    var restClient = new RestClientBuilder()

    var response = restClient.Function.Post(libraryName, functionName, functionInputParameters, published: true);
    var responseJson = response.GetJsonResult();

    DataSet resultDS = JsonConvert.DeserializeObject<DataSet>(responseJson["baqOutput"].ToString());

    epiUltraGridC1.DataSource = resultDS;

Open Epicor Help.

Search for “Calling Function from Client Customization”

Unfortunately unless he is in 2022.X this won’t work @klincecum that REST library helper thing was royally broken in 10.X.700.X version of Epicor. But he may be lucky if he is in the right point release, so try that first @JMyers56

If that doesn’t work you can use my helper library too but that requires some setup, you need to download and distribute the client DLL etc. I have some code I can provide but @klincecum 's suggestion is a lot cleaner (if it works)

You two are BOTH TERRIFIC! I’ll definitely try it first Jose, and let you know if I need further help!

I knew it was broken in some version, but was hoping this wasn’t one :frowning:

He could also bring in RestSharp.

Folks, I hate to be a bother, but do you have an example for looping through the QueryExecutionTable and loading the BAQ parameters from the function parameters, or how to create each parameter in code? All of the examples I’ve seen so far are using the widgets, and I’d prefer to keep using code.

Looping through, not currently, but I can probably do that real quick. In the meantime, here
is how you would build them from scratch:

Here is one way. There are countless ways to skin this cat.

I added a DataSet to the input parameters, it is paramDS.

CallService<DynamicQuerySvcContract>( svc =>
    QueryExecutionTableset qeTS = svc.GetQueryExecutionParametersByID(baqName);   
    foreach(DataRow dsParam in paramDS.Tables["Parameters"].Rows)
        var paramRow = qeTS.ExecutionParameter.Where(x => x.ParameterID == dsParam["ParameterID"].ToString()).First();
        if(paramRow != null)
            paramRow.ParameterValue = dsParam["ParameterValue"].ToString();
            paramRow.ValueType      = dsParam["ValueType"].ToString();
            paramRow.IsEmpty        = Convert.ToBoolean(dsParam["IsEmpty"]);

    baqOutput = svc.ExecuteByID(baqName, qeTS);

Here is the JSON for the call:

	"baqName": "KEV_ABCParams",
	"paramDS": {
		"Parameters": [{
				"ParameterID": "parm1",
				"ParameterValue": "Mark Wonsil will never live down the Chicken Parm Joke.",
				"ValueType": "nvarchar",
				"IsEmpty": false
				"ParameterID": "parm2",
				"ParameterValue": "I love beating a dead horse.",
				"ValueType": "nvarchar",
				"IsEmpty": false

Here is the return data from the function:

  "baqOutput": {
    "Results": [
        "ABCCode_Company": "MYCOMPANY",
        "ABCCode_ABCCode": "A",
        "ABCCode_CountFreq": 3,
        "ABCCode_ExcludeFromCC": false,
        "ABCCode_StockValPcnt": 0,
        "ABCCode_PcntTolerance": 0,
        "ABCCode_CalcPcnt": false,
        "ABCCode_CalcQty": false,
        "ABCCode_CalcValue": false,
        "ABCCode_QtyTolerance": 0,
        "ABCCode_ValueTolerance": 0,
        "ABCCode_ShipToCustNum": 0,
        "Calculated_Parameter1": "Mark Wonsil will never live down the Chicken Parm Joke.",
        "Calculated_Parameter2": "I love beating a dead horse."
    "Errors": [],
    "ExecutionInfo": [
        "Name": "ExecutionTime",
        "Value": "17.9041"

Unless your parameters list is extensive however, I would just pass them as arguments and
push them in that way though.

No variables were parmed in the making of this post.