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

> Source: https://netray.co/erp-help/epicor-function-custom-code-c-sharp-examples
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: ERP Help

## 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.

## Kind

advanced

## System

epicor

## Erp

Epicor Kinetic

## Module

Epicor Functions / Custom code

## Query

epicor function custom code

## Alternate Queries

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

## Applies To

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

## Steps

### Write and use a function with custom code

**Items:**

- Open Epicor Function Maintenance and create a library if one does not exist, then a new function inside it with an ID and description.
- Define the request parameters (inputs) and response parameters (outputs) with names and types.
- Open the designer and add a custom code block, or switch to the code view, and write the C# using the parameter names as variables.
- Declare any services (for example the Dynamic Query service) or required libraries the code uses.
- Set the function to the right access level and check it compiles using the Validate or Compile action.
- Use the test area to run the function with sample inputs and inspect outputs and errors.
- Call 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.

## Sections

### Signature and a simple example

**Body:**

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.

**Code:**

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

### Reading data and handling errors

**Body:**

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.

**Code:**

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

### Calling it from BPM, Application Studio and REST

**Body:**

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.

## 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.

## Ai Angle

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.

## Faq

### What is an Epicor Function?

**Answer:** 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?

**Answer:** 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?

**Answer:** 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?

**Answer:** 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.

## Search terms

epicor function custom code, epicor function c# example, epicor kinetic functions, epicor function request response parameters, call epicor function from bpm, epicor function application studio, epicor function library, epicor kinetic custom code

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
