AdvancedEpicor KineticBPM / Transactions

Epicor BPM TxScope: Standard vs In-Transaction Directives and When Functions Need a Transaction

Question
epicor bpm txscope

Also searched as

  • epicor bpm transaction scope
  • epicor bpm scope
  • epicor bpm standard vs in transaction
  • epicor function requires transaction

Short answer

A transaction scope groups database writes so they commit or roll back together. In Epicor BPM, a Standard directive runs outside the business object's database transaction, while an In-Transaction directive runs inside it, so an exception rolls back the whole save. In custom code you open your own scope with IceContext.CreateDefaultTransactionScope and call Complete.

Applies to: Epicor Kinetic and 10.x BPM and Epicor Functions. Behaviour of Standard versus In-Transaction depends on the method and processing stage, so read your release documentation for details.

How to choose and use transaction scope

  1. 1Decide whether your change must roll back if the main save fails. If yes, use an In-Transaction directive; if you are only validating or sending a notification, Standard is enough.
  2. 2In Method Directive Maintenance, set the directive type when creating it. It cannot always be changed afterward, so recreate if needed.
  3. 3For your own writes in custom code, wrap them in a transaction scope block.
  4. 4Call Complete on the scope only when every step succeeded. Leaving without Complete rolls back.
  5. 5Keep the scope short. Do lookups before it, writes inside it.
  6. 6Avoid calling slow services, email or web requests inside a transaction.
  7. 7Test a failure case on purpose and confirm that data rolled back.

Standard versus In-Transaction

Business object methods like Update open a database transaction around the save. An In-Transaction directive runs inside that transaction. If it throws, the entire save rolls back, which is the safe choice for rules that must stay consistent with the saved data, such as updating a related record at the same moment.

A Standard directive runs outside the database transaction. Pre-processing standard directives are ideal for validation and messages. Post-processing standard directives run after commit, so a failure there does not undo the save, and any writes they make are separate. In-transaction directives hold locks for longer, so keep them quick.

TxScope in custom code and functions

In custom code, create a scope with the Epicor context helper and wrap the writes. Without Complete, the scope rolls back when disposed. If the code runs inside an In-Transaction directive, the outer transaction still controls the final commit.

Epicor Functions run in their own context. Depending on your release, the function definition offers a setting that says whether it requires a transaction, and calling code can add its own scope. If a function writes several tables, make it transactional so partial writes cannot remain. Check the function options in Function Maintenance for your release.

using (var txScope = IceContext.CreateDefaultTransactionScope())
{
    var rec = Db.UD01.Where(u => u.Company == Session.CompanyID && u.Key1 == "A").FirstOrDefault();
    if (rec != null)
    {
        rec.Number01 = rec.Number01 + 1;
        Db.Validate();
    }
    txScope.Complete();
}

Rollback and locking pitfalls

Long transactions block other users. If you query a big table inside an In-Transaction directive, other sessions wait for locks until commit. Move reads out and keep only the writes inside.

Rollback also reverses your writes but not side effects such as emails, files written to disk or calls to external systems. Do those after commit in a Standard post-processing directive. Nested updates to the same record can trigger record-in-process style errors; see the update vs UpdateExt page.

Try it here, free

Epicor BPM Directive Overhead Calculator

Open full tool

See how many milliseconds and server hours your BPM directives add per transaction and per day.

Common pitfalls

  • !Forgetting Complete, so the writes silently roll back.
  • !Sending email or calling an API inside a transaction, then rolling back.
  • !Running large searches inside an In-Transaction directive and blocking users.
  • !Using a Standard post-processing directive for writes that must be atomic with the save.
  • !Swallowing exceptions in custom code so the transaction commits a partial change.

How an ERP-grounded AI assistant handles this

Transaction choices are easy to get wrong, so a reviewer helps. An assistant can read a directive and point out external calls inside a transaction, a missing Complete, or a long query in an In-Transaction block. It reports; your developer decides.

Frequently asked questions

What is the difference between Standard and In-Transaction directives in Epicor?

Standard directives run outside the business object's database transaction. In-Transaction directives run inside it, so an exception rolls back the save. Choose In-Transaction for rules that must be atomic with the data.

Do I always need a TxScope in BPM custom code?

No. If your code is only validating, you do not. Use a scope when you write more than one record and need them to commit or roll back together, outside an existing In-Transaction directive.

When does an Epicor function need a transaction?

When it changes several records that must stay consistent. Check the function options in your release and test a failure to confirm rollback.

Why did my data roll back?

Either an exception occurred inside the transaction, or the scope was disposed without calling Complete. Check the server log for the exception.

Related

How-to

Epicor BPM: Update a UD Field, a PO Cost or a Table, and Update vs UpdateExt

From a BPM you can update data three ways: change the incoming temp table row (best for the record being saved), call a business object Update or UpdateExt on another record, or write through Db and call Validate. UpdateExt returns errors in the dataset instead of throwing. A record in process error means the record is already being saved in the same call chain.

Error fix

Epicor BPM Runtime Error: Where to Look and How to Fix It

A BPM runtime error is an exception thrown while a directive runs, so the user's save or action fails. Find the directive name and line in the client trace or server log, then check the usual causes: a null reference in custom code, a directive that no longer compiles after a change, conflicting directive order, or a lock or validation error from a nested update.

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 BPM Custom Code Examples: Set, Query, Validate, Call and Refresh

A BPM Custom Code block is a C# snippet that runs inside a Method or Data directive and can read the incoming temp tables (ttOrderHed, ttOrderDtl and so on), query the database through Db, and call business objects. Below are tested-pattern examples for setting a field, looking up a record, validating and raising an error, and calling a service, plus how to make the client see data you changed.

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

AI on your ERP

Integrations

Comparisons

Software