Copy and paste is fast. Right up until the bug report.
The pain
The same rule was copied into seven pages. It changed, someone updated three of them, and now they disagree.
Why it happens
Duplicated logic means every change has to be found and repeated by hand, and something always gets missed.
Before: Copied everywhere
// Customer Card
if Rec."Credit Limit (LCY)" > 50000 then
Rec.TestField("Payment Terms Code");
// Plus 6 more copies across pages,
// with 3 different limits
After: One procedure, one place
codeunit 50180 "DF Credit Rules"
{
procedure CheckTerms(Customer: Record Customer)
begin
if Customer."Credit Limit (LCY)" > 50000 then
Customer.TestField("Payment Terms Code");
end;
}
// Everywhere else:
CreditRules.CheckTerms(Customer);
The result
Change the rule once and every page follows. Fewer bugs, faster changes, easier updates.
Tip: Better yet, move the 50,000 limit into a setup table. See Monday’s teardown.
Download this teardown as a PDF
Got a Business Central problem like this? Free 30 minute review of your setup. Senior Microsoft certified developers, and you talk to the person writing the code. Contact Dataflow Solutions.
