# Epicor Kinetic Custom Code: LINQ Delete and Variables in Application Studio Flows

> Source: https://netray.co/erp-help/epicor-kinetic-custom-code-linq-delete-flow-variables
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: ERP Help

## Short answer

Two different things are called custom code in Kinetic. Server side C# in BPMs and Epicor Functions can delete rows with LINQ by selecting the rows and removing them from the Db context, then validating. Client side Application Studio logic uses event flows with variables that you set in one widget and read in the next. Keep them separate: the browser never touches the database directly.

## Kind

advanced

## System

epicor

## Erp

Epicor Kinetic

## Module

Application Studio / BPM custom code

## Query

epicor kinetic custom code linq delete

## Alternate Queries

- epicor kinetic custom code variable in flow
- epicor kinetic flow down
- epicor kinetic themes
- epicor kinetic controls compendium

## Applies To

Epicor Kinetic 2021 and later. BPM and Functions code is C#; Application Studio events use the designer. Check release help for exact widget names.

## Steps

### Delete rows with LINQ on the server

**Items:**

- Decide where the delete belongs: a method directive (BPM) on the business object or an Epicor Function you call from an event.
- In a custom code block, query the table with LINQ, for example Db.JobMtl.Where(m => m.Company == Session.CompanyID && m.JobNum == jobNum).
- Materialise the result with ToList() before deleting, so you are not changing the collection you are iterating.
- Delete each row using the context method for the table, then call Db.Validate() at the end of the block.
- Wrap the block in try and catch, and raise a business exception with a clear message if the delete is not allowed.
- Test in a non-production company with a test user, then log which rows were removed so you can audit the change.

## Sections

### A LINQ delete pattern

**Body:**

The safe pattern is: select, materialise, delete, validate. Do not delete inside the lambda, and always filter by Company, because the context holds data for the company in session only through your filter.

Deleting through the context respects database constraints but may skip business rules that the screen would apply. Prefer calling the standard business object delete method when it exists and only use direct deletes for housekeeping tables you own.

**Code:**

- var rows = Db.UD01
  .Where(r => r.Company == Session.CompanyID && r.Key1 == key)
  .ToList();
foreach (var r in rows)
{
  Db.UD01.Delete(r);
}
Db.Validate();

### Variables in Application Studio flows

**Body:**

In Application Studio, an event flow runs a sequence of widgets. To carry a value from one widget to another, store it in a flow variable set by an earlier widget and refer to it in later ones, rather than re-reading a control.

Keep variable names clear and scoped to the event. If a value must survive between events, put it in a page-level variable or a data view column and note that in your design document.

### Layers, themes and controls

**Body:**

Customisations are saved in layers, so you can keep changes separate from the base app and survive upgrades. Themes control look and feel across the application and are managed in the theme settings rather than per control.

Epicor documents the available controls and their properties in its Application Studio help. Use that reference to check which properties and events a control supports before building around it.

## Pitfalls

- Deleting while enumerating the same query, which throws an exception.
- Forgetting the Company filter and touching unrelated rows.
- Skipping Db.Validate() so changes are not committed.
- Using direct deletes where the business object method enforces rules you need.
- Putting business logic in the client where users can bypass it.

## Ai Angle

For code like this, an assistant trained on your own BPM and function library can draft the LINQ for review and explain which tables a delete touches. It writes nothing into production; a developer reviews and deploys it under change control.

## Faq

### How do I delete records with LINQ in Epicor?

**Answer:** Query with Db.Table.Where(...), call ToList(), delete each row through the context, then call Db.Validate(). Filter by Company, and prefer the standard business object delete when one exists.

### Can Application Studio code delete database rows?

**Answer:** Not directly. Client events call business object methods or functions. Do the delete in a BPM or Epicor Function and call it from the flow.

### How do I pass a value between widgets in a flow?

**Answer:** Set a flow variable in one widget and read it in later widgets of the same event. For wider scope use page-level variables or data view columns.

### Where are the controls and their properties documented?

**Answer:** In Epicor's Application Studio help, which lists controls, properties and events. Check the version matching your release.

## Search terms

epicor kinetic custom code linq delete, epicor bpm linq, epicor kinetic variable in flow, epicor application studio event flow, epicor kinetic themes, epicor kinetic controls, epicor db.validate

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