How to Build a Generic Table Update Method in Acumatica Using C# Generics
In many Acumatica customization projects, developers encounter scenarios where multiple DACs (Data Access Classes) need to be updated in nearly identical ways. Often, the only difference is the table name and field name being updated — yet developers end up writing dozens of separate methods for each table.
This not only increases maintenance overhead but also clutters your codebase with repetitive logic.
This article shows how to create a generic C# method using the Acumatica Framework that allows you to update any table and field combination — without hardcoding the table or field names. You'll be using Acumatica's PXDatabase.Update, PXView, and BqlCommand classes to keep everything strongly typed and safe.
The typical pattern for updating a record in Acumatica using PXDatabase.Update looks like this:
PXDatabase.Update<APInvoice>(
new PXDataFieldAssign(typeof(APInvoice.suppliedByVendorID).Name, PXDbType.Int, newValue),
new PXDataFieldRestrict(typeof(APInvoice.suppliedByVendorID).Name, PXDbType.Int, oldValue)
);
This is fine for a single table. But what if you need to do the same kind of update across 10 or 50 DACs with different fields?
Instead of duplicating this logic, we can build a single generic method that works for any table and field combination.
Here’s how you can define a reusable method that accepts a DAC type (T) and a field type (TField) as generic parameters:
You get type-safety, reusability, and centralized control over your update logic — all in one method.
Notes and Best Practices
- This method assumes you're working with int fields. You can overload or extend the method to handle other data types.
- PXDatabase.Update executes SQL directly and bypasses Acumatica’s business logic. Only use this when it's safe to update the field directly (e.g., for integration cleanup tasks or mass updates where business logic is not required).
- Use PXView to confirm the record exists before calling Update, to avoid unnecessary database hits or failures.
- Always wrap this kind of logic in proper transaction handling if you're performing multiple updates.