Back to articles
X++ Development

X++ update_recordset vs update() vs doUpdate(): when each one is safe in D365FO

A practical guide to choosing the right D365FO update pattern. Learn when set-based updates are appropriate, when table logic still runs, and why doUpdate is usually the wrong escape hatch.

X++ update_recordset vs update() vs doUpdate(): when each one is safe in D365FO#

If you work in D365FO long enough, you eventually hit this decision: should you update records with update_recordset, loop through records and call update(), or use doUpdate() to force the write through?

The short version is:

  • update_recordset is for set-based database updates when you want performance.
  • update() is for normal record updates where table logic, validations, and extensions should run.
  • doUpdate() bypasses that logic and should be avoided in almost all custom code.

This sounds simple, but in real projects it is one of the easiest places to introduce data integrity bugs.

The basic difference#

Microsoft’s X++ data access docs separate these three paths clearly. update() updates the current record and system fields. doUpdate() updates one row but skips table logic, database event handlers, Chain of Command on update(), and the update() call itself. update_recordset updates multiple rows in a single database trip, but it can fall back to row-by-row behavior in some cases. (learn.microsoft.com)

That means the choice is not just about syntax. It changes which business logic runs.

When I would use update_recordset#

Use update_recordset when all of these are true:

  • You are updating many rows.
  • The new values are deterministic from the current row or joined rows.
  • You do not need table update() logic to run for each record.
  • You are comfortable with the fact that the database may handle it as a set operation instead of a loop.

Microsoft documents update_recordset as a record set–based operator that updates multiple records in one trip to the server, which is why it is the usual choice for bulk changes. (learn.microsoft.com)

Example:

X++
CustTable custTable;

ttsBegin;
update_recordset custTable
    setting CreditMax = custTable.CreditMax + 1000
    where custTable.CreditMax > 0;
ttsCommit;

That is a good pattern when you are doing a pure data adjustment and you know no per-record custom logic must fire.

The important catch with update_recordset#

update_recordset is fast, but it does not behave like a normal buffer update in every situation. If the table has an overridden update() method, D365FO can fall back to a classic loop and update one record at a time. Microsoft also notes that set-based operations can fall back to record-by-record operations in some cases. (learn.microsoft.com)

So you should not assume update_recordset always means “single SQL statement, always.” In practice, it means “prefer set-based execution when the framework can safely do it.”

That matters for performance expectations and for testing. A change that looks harmless in dev can become much slower if the table design or extensions force row-by-row processing.

When I would use update()#

Use update() when you want normal application behavior.

That usually means:

  • table validations should run,
  • business logic in the table should run,
  • Chain of Command on update() should run,
  • event handlers should run,
  • system fields should be handled normally. (learn.microsoft.com)

Example:

X++
CustTable custTable;

ttsBegin;
select forUpdate custTable
    where custTable.AccountNum == "US-001";

if (custTable)
{
    custTable.CreditMax += 1000;
    custTable.update();
}

ttsCommit;

This is the safer choice when the record is part of standard business process logic and you want the platform to enforce the usual rules.

Why doUpdate() is usually a bad idea#

doUpdate() is the one people reach for when update() gets in their way. The problem is that it gets in the way for a reason.

Microsoft explicitly warns that doUpdate() skips all logic, including database event handlers, Chain of Command on update(), and the update() call itself. Microsoft also says it is considered bad practice and is not recommended. (learn.microsoft.com)

In other words, doUpdate() is not just a “faster update.” It is a bypass.

That makes it risky because you can silently skip:

  • validations,
  • audit-related behavior,
  • custom logic added by other extensions,
  • side effects the application expects to happen.

Example of the dangerous pattern:

X++
CustTable custTable;

ttsBegin;
select forUpdate custTable
    where custTable.AccountNum == "US-001";

if (custTable)
{
    custTable.CreditMax += 1000;
    custTable.doUpdate();
}

ttsCommit;

This may appear to work, but it bypasses the normal update pipeline. Unless you have a very specific reason and understand every side effect, do not use it in custom code.

A practical rule of thumb#

This is how I usually decide:

  • Use update_recordset for large, set-based updates where business logic does not need to run per row.
  • Use update() for normal record changes where platform and table logic should run.
  • Avoid doUpdate() unless you are dealing with a special internal scenario and you have confirmed that bypassing logic is safe.

If you are unsure, choose update() first. It is slower than a clean set-based update, but it is usually safer.

Transaction scope still matters#

None of these methods remove the need for correct transaction handling. X++ transactions are still controlled by ttsBegin, ttsCommit, and ttsAbort, and Microsoft describes ttsAbort as discarding changes in the current transaction while throw automatically aborts the current transaction. (learn.microsoft.com)

So even when you use update_recordset, you still need to think about transactional boundaries.

A common mistake is assuming that a bulk update is somehow “outside” normal transaction rules. It is not.

Common mistake: using doUpdate() to fix a validation problem#

If update() fails, the instinct is often to switch to doUpdate() so the change will go through.

That usually means one of three things:

  1. your data is invalid,
  2. your update order is wrong,
  3. a business rule is being bypassed that should probably stay in place.

The right fix is normally to correct the data or adjust the process, not to suppress the framework behavior.

Common mistake: using update_recordset when you actually need per-row logic#

Another easy mistake is using update_recordset because it looks cleaner, then later discovering that nothing in update() ran.

If your code depends on:

  • field validations,
  • derived values,
  • workflow-related hooks,
  • event handlers,
  • custom audit logic,

then a set-based update may not be the right tool.

In most D365FO projects, I would follow this pattern:

  1. Start with the simplest correct business behavior.
  2. Use update() when logic matters.
  3. Optimize to update_recordset only when you have confirmed the change can be done safely in a set-based way.
  4. Treat doUpdate() as an exception path, not a normal technique.

That keeps the code understandable and reduces the chance that a later extension breaks your update logic.

Bottom line#

The question is not just “which update method is faster?” The real question is “which business logic do I need to preserve?”

If you remember nothing else:

  • update_recordset = bulk update, best for performance.
  • update() = normal update, best for correctness.
  • doUpdate() = bypass, usually not worth the risk.

Sources#

Was this article helpful?Sign in to vote

Missing something?

Suggest a topic you'd like to see covered next. The most requested topics help shape future XppForge documentation.

Sign in to suggest a topic