General X++ Development
How do I retry a transaction after an UpdateConflict exception?
How do I retry a transaction after an UpdateConflict exception?
1 answer
Write an answerUse retry, but put a limit on it.
A common D365FO pattern uses the OCC retry macros:
#OCCRetryCount
try
{
ttsBegin;
// Select for update and update logic.
ttsCommit;
}
catch (Exception::UpdateConflict)
{
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
retry;
}
throw;
}Do not create an unlimited retry loop. If the same conflict keeps happening, eventually let the error surface so you can fix the actual problem.
Know the solution?
Sign in to contribute an answer and build your community reputation.
Sign in to answer