0054

Cue Styles from Thresholds

Extensibility
Easy
cues
system-application
role-center
enum

Cue Styles from Thresholds

Finance's role center shows a Receivables cue with the company's total overdue amount, and management wants its colored indicator to work for everyone: green while the amount is comfortable, yellow once it passes a warning level, red past a critical level. Administrators can set this up per company in the UI, but your app must ship it as code — a one-time registration plus a helper that any code can ask "which style applies to this amount right now?". No page or role center is needed in this task; it is pure table + enum logic.

Requirements

  1. Create a table named "Receivables Cue" with a field named "Overdue Amount" of type Decimal. The rest of the table design is up to you, but the grading inserts a record without setting any key fields, so the primary key must accept its default values.
  2. Create a codeunit named "Receivables Cue Style" with two public procedures:
procedure RegisterThresholds(LowerThreshold: Decimal; UpperThreshold: Decimal): Boolean
procedure StyleFor(Amount: Decimal): Enum "Cues And KPIs Style"

Rules the tests enforce:

  • RegisterThresholds records a company-wide (all users) indicator setup for the "Overdue Amount" cue field with exactly three bands: Favorable for low amounts, Ambiguous for the middle band, Unfavorable for high amounts, split by the two thresholds. It returns true when the setup was recorded.
  • If a setup for this cue field already exists, RegisterThresholds must leave the existing setup untouched and return false.
  • StyleFor resolves the style for an amount from the recorded setup: strictly below LowerThreshold → Favorable; from LowerThreshold up to and including UpperThreshold → Ambiguous; strictly above UpperThreshold → Unfavorable. Note the boundaries: an amount exactly equal to either threshold is Ambiguous.
  • When nothing has been registered for the cue field, StyleFor returns None.
  • The registration must outlive the codeunit instance that made it: the tests call RegisterThresholds and StyleFor on two separate instances of your codeunit, so thresholds kept in codeunit variables will not pass.

Two things worth knowing before you start: the storage behind the admin's cue indicator setup is internal to the System Application, so your code cannot read or write it directly — the platform offers extensions a small supported API for both directions, and finding it is the exercise. The tests always register with LowerThreshold < UpperThreshold; other combinations are not graded.

Pick all object IDs in the 50100–50199 range and reference every object outside your submission by name, never by literal ID. Captions are good practice but not graded.

What the tests check

The tests insert a "Receivables Cue" record with a generated "Overdue Amount" and read it back; register generated thresholds through one instance of "Receivables Cue Style" and resolve amounts through another — below, between, above, and exactly at each of the two thresholds; check that the first registration returns true, that a second registration returns false and leaves the first thresholds in force; and check that StyleFor returns None when nothing was registered. The tests also verify the interop both ways: after RegisterThresholds succeeds, the registration must be visible to the platform's own cue-indicator setup (a platform-level attempt to record a setup for the same cue field is rejected as a duplicate), and StyleFor must resolve a setup that the tests record through the platform's cue-indicator API directly — so keeping thresholds in your own table or variables will not pass.

Learn More

Hint 1
Everything you need already ships with the platform: the colored bar on a cue is driven by the same threshold-and-style setup an administrator enters on the Cue Setup page, stored per table field. The System Application exposes a small supported API over that storage — your codeunit should not invent its own.
Hint 2
The System Application module is called Cues and KPIs, and its facade codeunit exposes InsertData — which writes one company-wide setup entry (low style, threshold 1, middle style, threshold 2, high style) and returns whether the insert happened — and SetCueStyle, which resolves the style for an amount through a var parameter. Identify your cue field with Database::"Receivables Cue" and ReceivablesCue.FieldNo("Overdue Amount"), never with literal IDs.
Hint 3
RegisterThresholds is a single exit(CuesAndKPIs.InsertData(...)) passing Database::"Receivables Cue", ReceivablesCue.FieldNo("Overdue Amount"), then Favorable, LowerThreshold, Ambiguous, UpperThreshold, Unfavorable — InsertData already returns false when the entry exists. StyleFor declares a local Enum "Cues And KPIs Style" variable, calls CuesAndKPIs.SetCueStyle with the same table and field plus Amount and the variable, and exits with it.
ALBusiness Central 28.4
Press Compile to check your code compiles — Submit runs the tests.
The code editor is desktop-only
Open this problem on a computer to write and run code. Reading the description, tests and discussion works fine here.