A Filter the Caller Can't Break
Your regional sales apps all get their customer data the same way: a helper hands out a Customer record already limited to one salesperson, and downstream code — reports, exports, cleanup jobs written by other teams — filters that record however it likes. Last month a cleanup job called Reset() on the record it had been handed and exported the entire customer table to one very surprised salesperson. A week before that, an "optimization" retargeted the record to a different salesperson with a plain SetRange.
The fix is a scope the caller cannot break, no matter what filtering calls they make afterwards — the way a page's own view filters sit out of reach of everything the user does in the filter pane, narrowable but never removable.
Requirements
Create a codeunit named "Customer Scope Guard" with one public procedure:
procedure ScopeToSalesperson(var ScopedCustomer: Record Customer; SalespersonCode: Code[20])Rules:
- After the call,
ScopedCustomersees exactly the customers whose"Salesperson Code"equalsSalespersonCode— counting, finding and iterating all respect the scope, and a salesperson with no customers yields an empty record set.
Solve it with Pro
You’re reading the opening of the statement. Pro unlocks the whole problem:
- The full statement
- Starter code in the browser editor
- 8 grading tests, run on Business Central 28.5
- 3 hints
- The reference solution
Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.
Already on Pro? Sign in