Epicor ERP can you call an Epicor Function within a Customization

3.3k Views Asked by At

Epicor ERP 10.2.500 has been recently released with the addition of Epicor Functions. They can be called from within Method and Data Directives.

Do anybody has been able to do so with a Form Customization within Epicor?

4

There are 4 best solutions below

1
On

If you create your own dll that calls the EpicorFunction you can use it within the customization. Still looking for a way to call them directly.

1
On

Haven't done it myself personally, but looking into the first post release notes about it here leads me to believe there is no out of the box solution, yet in this version/initial release.

However I'm sure you could do a HTTP request from within the Epicor customization if you have the REST API enabled in your environment.

0
On

REST endpoint is the recommended way to perform the function call as pointed out by a-moreng.

If for some reason you cannot use this, you can use a passthrough method to any server-side BO via a customization Adapter. For instance, create an updatable BAQ which you can call from a customization using the DynamicQueryAdapter.

  • Pick an arbitrary table and field to save the BAQ.
  • Create three string parameters to store the Function library name, the function name, and a delimited list of parameters.
  • On the GetList method, create a Base Processing Directive.
  • Split your delimited parameter list and convert them to the appropriate datatypes.
  • Use the resulting variables to call your function.
  • If desired, you can pass return variables into the ttResults of the BAQ
0
On

This is possible via a REST call to your function API. In this case, I had a function that sent an email from some inputs.

private void epiButtonC1_Click(object sender, System.EventArgs args)
{
    //API Key is included in the query param in this example. 
    var request = (HttpWebRequest)WebRequest.Create("https://{appserver}/{EpicorInstance}/api/v2/efx/{CompanyID}/{LibraryID}/{functionName}/?api-key={yourAPIKey}");
    request.Method = "POST";
    //All REST v2 requests also sent with authentication method (Token, Basic)
    //This should be Base64 encoded
    string username = "userName";
    string password = "passWord";
    string encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
    request.Headers.Add("Authorization", "Basic " + encoded);

    //Add body to correspond to request signature
    request.ContentType = "application/json";
    using(var writer = new StreamWriter(request.GetRequestStream()))
     {
        var values = new Dictionary<string, string>;
          {
            {"toEmailAddress", "[email protected]"},
            {"fromEmailAddress","[email protected]"}, 
            {"body","This is the body"},   
            {"subject","Hello from Client Code!"}
        };
    string json = JsonConvert.SerializeObject(values);
    writer.Write(json); 
    }   
    using (var response = request.GetResponse()) 
    using (var reader = new StreamReader(response.GetResponseStream()))
    {
      var result = reader.ReadToEnd();
      epiTextBoxC1.Text = result.ToString();
    }

}