AdvancedEpicor KineticEpicor Functions / Custom code

Epicor Function Custom Code: C# Signature, Parameters and Calling It

Question
epicor function custom code

Also searched as

  • epicor function c# example
  • epicor kinetic function request response parameters
  • call epicor function from bpm
  • call epicor function from application studio

Short answer

An Epicor Function is a reusable server-side routine with typed request and response parameters. Its body is C# you write in the function editor, either as a custom code block or as widgets. Define the inputs and outputs, write the code, test it, then call it from a BPM, from Application Studio, from another function or through the REST API.

Applies to: Epicor Kinetic Epicor Functions (2021 and later). Editor features, widget names and available namespaces vary by release.

Write and use a function with custom code

  1. 1Open Epicor Function Maintenance and create a library if one does not exist, then a new function inside it with an ID and description.
  2. 2Define the request parameters (inputs) and response parameters (outputs) with names and types.
  3. 3Open the designer and add a custom code block, or switch to the code view, and write the C# using the parameter names as variables.
  4. 4Declare any services (for example the Dynamic Query service) or required libraries the code uses.
  5. 5Set the function to the right access level and check it compiles using the Validate or Compile action.
  6. 6Use the test area to run the function with sample inputs and inspect outputs and errors.
  7. 7Call the function from a BPM (a Call Epicor Function widget), from an Application Studio event (a function call action), from another function, or from the REST API.

Signature and a simple example

The function signature is the set of request and response parameters. Think of it like a method: keep inputs minimal, typed, and documented in the description. Request parameter names become local variables in your code, and response parameters are assigned before the function ends.

A trivial example: take a part number and quantity, return a formatted label. It is useful for learning the editor before moving to database logic.

// Request: partNum (string), qty (decimal)
// Response: label (string)
label = string.Format("{0} x {1:0.##}", partNum, qty);

Reading data and handling errors

For data, call a BAQ through the Dynamic Query service as in our BAQ-from-function page, or in recent versions query tables with LINQ on the Db context. Prefer a read of exactly the columns needed, and avoid loading large sets into memory.

To report a problem to the caller, throw a business exception with a clear message so BPM or Application Studio can show it. Catching and swallowing errors leads to functions that look fine and quietly do nothing.

if (qty <= 0)
    throw new Ice.BLException("Quantity must be greater than zero.");

Calling it from BPM, Application Studio and REST

In a BPM, use the function widget so the call is visible in the directive flow and its outputs map to variables. In Application Studio, call the function from an event rule and bind its result to the view, which keeps business logic out of the client layer. Through REST, call the function's endpoint with the request parameters as JSON, using a token or API key.

Because a function is a single, tested unit, it is the right place for logic that several customizations share. Version functions with care: changing a signature breaks callers, so add new parameters rather than renaming old ones.

Try it here, free

Epicor Function Library Design Template

Open full tool

A design document for an Epicor function: signature, inputs, outputs, logic notes, security, test cases and sign off.

Common pitfalls

  • !Changing request or response parameter names after callers exist.
  • !Doing heavy data work in functions called from synchronous BPM directives.
  • !Swallowing exceptions, so failures are invisible to users.
  • !Not testing with a restricted user, since production security differs from the developer account.

How an ERP-grounded AI assistant handles this

A coding assistant grounded in your function libraries and BAQ catalog can propose a signature, draft the C# and flag callers that a signature change would break, for a developer to review and test. Netray can run this privately, including against on-prem Epicor, so your customization code stays inside your network.

Frequently asked questions

What is an Epicor Function?

It is a reusable server-side routine with defined inputs and outputs, written in C# or built with widgets, that you can call from BPMs, Application Studio, other functions and the REST API.

Where do I write the C# code?

In the Epicor Function designer, using a custom code block or the code view. Request parameters are available as variables and response parameters are set before the function ends.

Can I call a function from Application Studio?

Yes, from an event rule using a function call action, and bind the response to your view. Keep business logic in the function and presentation in the view.

How do I debug a function?

Use the built-in test area with sample inputs, add temporary log messages, and check the server logs for exceptions. Test again as a non-admin user.

Related

Advanced

How to create and call an Epicor Function

Open Function Studio from the main menu (Customization > Function Studio) or from inside a BPM designer's Call Context widget, define a Library and Function with typed inputs/outputs, write the logic in the C# widget, then compile and test with the built-in test harness before calling it from a BPM directive, a dashboard, or another function.

How-to

Epicor Function: How to Call a BAQ from C# (Functions and BPM)

To run a BAQ from an Epicor Function or a BPM code block, call the Dynamic Query service: get the query's execution parameters by BAQ ID, set any parameter values, run it with the execute-by-ID method, and read rows from the results table. Declare the service in the function so the platform can resolve it.

How-to

How to Create a BPM Method Directive in Epicor Kinetic

In Epicor Kinetic, open Business Process Management > Method Directive Maintenance (the BPM Workbench), pick the business object and method, choose Pre-Processing, Base Processing or Post-Processing, then add a condition and actions such as Show Message or Set Field. Enable it and test in a pilot company before production.

Advanced

Epicor Application Studio: understanding customization layers

Kinetic UI is built in layers loaded in order - Base (Epicor-delivered), Customization (Application Studio, company/layer-wide), Personalization (user- or role-specific, applied on top), and optionally Extended (packaged add-on layers) - and a change you make will not appear if a higher layer overrides the same control or if you are testing in the wrong layer context.

Error fix

Fixing Epicor BusinessObjectException: BPM Directive Errors

A BusinessObjectException that says "A Business Process Management (BPM) directive has raised the following error" means a directive on that business object stopped the transaction, either deliberately via a Raise Exception widget or accidentally via an unhandled .NET error in Custom Code. Expand the InnerException on the error dialog to see the real message and the directive name, then open BPM Designer for that object and method to find the widget that fired.

How-to

Fixing a Slow Epicor BAQ (Business Activity Query)

A slow BAQ in Epicor is usually caused by unindexed join columns, a subquery or calculated field forcing a table scan, or the BAQ pulling far more rows than the dashboard actually displays before filtering client-side. Fix it by reading the SQL Server execution plan Epicor generates, moving filters into the BAQ criteria instead of the dashboard filter panel, and replacing subqueries with joins where possible.

AI for ERP

AI for Epicor Kinetic, Beyond What Prism Covers

Add AI to Epicor Kinetic beyond Prism: private LLM over BAQs, BPM data, and REST v2, on-prem or private cloud, with honest guidance on when Prism already covers you.

Stuck on Epicor Kinetic?

Talk to engineers who work inside Epicor Kinetic every week, and who build private AI that answers these questions from your own ERP data.

Keep exploring

Free tools

ERP fixes and how-tos

Integrations

Comparisons

Software