Score Indicator PCF
The NumberControl is a Power Apps Component Framework (PCF) control that visually represents a numeric field using a colored circular indicator.
What the control does
-
Reads a numeric value from Dataverse.
-
Displays a small circle whose color changes based on the value range.
-
Shows the numeric value as a tooltip on hover.
-
Automatically updates when the field value changes.
User-facing behavior
-
Gray: No value (null or empty).
-
Green: Value between 0 and 10.
-
Yellow: Value between 11 and 20.
-
Red: Value greater than 20.
-
Hovering over the circle shows the current value.
This control is useful for quick visual status indicators, risk levels, scores, or thresholds without displaying the number itself.
Technical Description
1. Control Definition
-
Implements
StandardControl, following the PCF lifecycle. -
Uses generated input/output types from
ManifestTypes. -
Acts as a read-only visual control with no outputs.
2. Class Members
-
Stores the root HTML container provided by the PCF framework.
-
Used to render and update the UI.
3. init() – Initialization
-
Runs once when the control is created.
-
Stores the container reference.
-
No UI is rendered here.
-
No event handlers or data calls are initialized.
This keeps initialization lightweight and defers rendering to updateView().
4. updateView() – Rendering Logic
This method is called whenever:
-
The bound field value changes.
-
The form refreshes.
-
The control size or metadata changes.
a. Read numeric value
-
Safely converts the bound value to a number.
-
Handles
nullvalues correctly.
b. Reset the UI
-
Clears previous elements to prevent duplicate rendering.
c. Create the indicator
-
A simple HTML
divstyled as a circle. -
Fixed size (22×22 pixels).
-
Border added for visibility.
d. Apply color rules
-
Implements clear threshold-based logic.
-
Easy to extend or modify.
e. Add tooltip
-
Improves usability without cluttering the UI.
f. Render to DOM
-
Displays the indicator inside the PCF container.
5. getOutputs() – Output Handling
-
No data is written back to Dataverse.
-
The control is strictly display-only.
6. destroy() – Cleanup
-
No listeners or resources to release.
-
Safe to leave empty.
Comments
Post a Comment