Two Filters That Compile and Lie
A colleague left a small reporting codeunit behind before moving on. It compiles, it runs without a single error, and both numbers it produces are wrong: CountWithoutSalesperson reports every customer in the company, and CountInRange reports 0 whatever range it is asked for. Nobody noticed for weeks because nothing ever crashed — each bug is a filter that looks right and quietly does something else.
Your job is to make the two numbers true.
Requirements
The starter contains a codeunit named "Customer Queries" with two public procedures. Keep the codeunit name and both signatures exactly as they are:
procedure CountWithoutSalesperson(): Integer
procedure CountInRange(FromNo: Code[20]; ToNo: Code[20]): IntegerRules:
CountWithoutSalespersonreturns how manyCustomerrecords have a blank"Salesperson Code". A customer carrying any salesperson code must not be counted — the answer is never "every customer in the table".CountInRangereturns how manyCustomerrecords have a"No."fromFromNothroughToNo, both ends included: a customer numbered exactlyFromNoor exactlyToNocounts, the customers numbered just beforeFromNoor just afterToNodo not. WhenFromNoequalsToNo, the range is that single number.FromNoandToNoare plain customer numbers (letters, digits and hyphens only), andFromNonever sorts afterToNo.- Both procedures answer 0 when nothing matches, and neither may raise an error.
Each procedure is one filter away from correct: the fix belongs on the filtering line. Only the counts are graded — how you arrive at them is not.
Keep the object ID in the house range 50100–50199 and reference other objects by name, never by ID.
What the tests check
The grading tests run in a real company that already contains customers, so CountWithoutSalesperson is graded as a difference: a test calls it, adds a mix of customers with and without a salesperson code, calls it again, and asserts that the count grew by exactly the number of customers added without a code — by a generated number of them in one test, and by zero in another where every customer added carries a code. CountInRange is graded with exact counts on customers created under a generated number prefix: five ascending numbers of which the middle three are asked for (both boundaries in, both neighbours out), a range whose FromNo equals ToNo, a generated number of customers inside a wider range, and a range that holds no customer at all, which must return 0. Fixing only one of the two procedures leaves the other's tests failing.
Learn More
- Record.SetFilter Method — the reference for the method
CountWithoutSalespersoncalls. - Record.SetRange Method — the reference for the method
CountInRangecalls. - Entering criteria in filters — the filter expression syntax, including what
..means. - Filtering records with the SetRange, SetFilter, GetRangeMin, and GetRangeMax methods — the rules that govern how each of the two methods treats its arguments.