AdvancedEpicor KineticApplication Studio / BPM custom code

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

Question
epicor kinetic custom code linq delete

Also searched as

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

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.

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.

Delete rows with LINQ on the server

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

A LINQ delete pattern

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.

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

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

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.

Try it here, free

Epicor Application Studio Layer Checklist

Open full tool

A checklist for Kinetic Application Studio layers covering naming, scope, events, rules, security, testing and upgrade impact.

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

How an ERP-grounded AI assistant handles this

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.

Frequently asked questions

How do I delete records with LINQ in Epicor?

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?

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?

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?

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

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

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.

How-to

Epicor MRP Runs but Generates No Suggestions

When Epicor's MRP process completes without a job or purchase suggestion for a part you expect one for, the cause is almost always the part's own configuration (Part Class Type, Make Direct, Non-MRP flag, planning Time Fence) or the demand not being linked in a way MRP recognizes, not a defect in the MRP engine. Work through the part's Planning tab, its safety stock and lead time setup, and the demand source (sales order line status, job material requirement) before assuming the run itself failed.

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

Guides

AI on your ERP

Integrations

Comparisons

Software