General X++ Development

When should I use a transaction in X++?

Asked by Sunny Vasty· Aug 13, 2026· 1 answers

When should I use a transaction in X++?

SSunny Vasty75 reputation · answered Aug 13, 2026

Use a transaction when multiple database changes must succeed or fail together.

For example, if you update a header and several related lines and a partial update would leave the data inconsistent, those changes probably belong in the same transaction.

X++
ttsBegin;

// Related database changes.

ttsCommit;

Keep transactions as short as you reasonably can. Holding a transaction open while doing slow calculations or user interaction is asking for locking problems.