Hello Everyone,
During a recent Business Central project, I encountered a serious issue when modifying bulk records using Modify(True)
. The system froze, causing performance bottlenecks and making the process unusable. After troubleshooting, I realized that improper use of Modify(True)
was the root cause.
What Are Modify(True)
and Modify
?
Modify
: Saves changes to the database without triggering theOnModify
trigger.Modify(True)
: Saves changes and triggers theOnModify
trigger, executing any additional logic defined in the table.
What Went Wrong?
In my project, I was updating thousands of records using Modify(true)
, thinking it would ensure business rules were applied. However, this caused:
- Performance Bottlenecks – The
OnModify
trigger executed for each record, significantly slowing down the process. - Recursive Calls & Locking – If the
OnModify
trigger contained additionalModify(True)
calls, it created a loop, causing database locks. - System Hanging – The excessive load on the server caused Business Central to become unresponsive.
How to Fix It?
-
Use
Modify
Instead ofModify(true)
for Bulk Updates
If you don’t need the extra logic inOnModify
, useModify
to improve performance. -
Move Business Logic Outside of
OnModify
Instead of relying onOnModify
, consider executing necessary logic in an explicit function that you call after bulk modification. -
Use
DisableTrigger(True)
for Temporary Updates
IfOnModify
must be skipped temporarily, useRec.DisableTrigger(True);
before modifying records, then re-enable it afterward. -
Batch Processing
Instead of modifying all records at once, process them in smaller batches to prevent timeouts and locking issues.
Lesson Learned
Using Modify(True)
incorrectly can cause severe performance issues, especially when working with large datasets. Always evaluate whether triggering OnModify
is necessary and optimize accordingly.
Have you encountered similar challenges? Let’s discuss in the comments!
Reach out to me if you have any questions or suggestions.
Check out other blogs, if you haven't already.
No comments:
Post a Comment