nxCountByEnum macro is a core Nextedy Solutions Velocity component that counts work items by enumeration field value. It aggregates work items into buckets based on enum options (such as ASIL levels, Action Priority, severity ratings, or risk levels) and tracks unclassified items. This macro is essential for generating compliance dashboards, risk summary cards, and distribution matrices across TestAuto2 — Automotive Safety Solution.
Overview
nxCountByEnum processes a collection of work items and produces a count distribution across all valid enum values for a specified field. It returns a LinkedHashMap of counts keyed by enum option ID, plus a separate count of unclassified items (null values).
Common Use Cases:
- ASIL distribution summaries (counts of QM, A, B, C, D hazards)
- Action Priority classification (counts of H, M, L failure modes)
- Risk level distribution (counts of low, medium, high, critical)
- Severity/Likelihood bucketing for matrix reports
- Compliance readiness metrics
Macro Signature
| Parameter | Type | Required | Description |
|---|---|---|---|
$items | List | Yes | Collection of work items to count (e.g., all hazards, all failure modes) |
$fieldName | String | Yes | Enum field name to count by (e.g., "classification", "actionPriority", "severity") |
Output Variables
After callingnxCountByEnum(), the following global Velocity variables are set:
| Variable | Type | Description |
|---|---|---|
$nxEnumCounts | LinkedHashMap<String, Integer> | Map of enum option IDs → count. Keys are the enum reference IDs (e.g., "a", "d", "qm"), values are item counts. Ordered by enum definition. |
$nxEnumUnclassified | Integer | Count of items where the field is null or missing (not yet classified) |
$nxEnumTotal | Integer | Total count of all items in the input collection |
Usage Pattern
Real-World Examples
Example 1: ASIL Distribution for ISO 26262 HARA Report
Example 2: Action Priority Distribution for DFMEA Summary
Example 3: Severity Level Distribution for Risk Matrix
Implementation Notes
Enum Field Resolution
The macro handles enum field access via Polarion’s API:"qm", "a", "h", "medium"). Keys are case-insensitive when matching against enum definitions.
Null/Unclassified Handling
Items with:- No value set for the field (null)
- Empty field reference
- Field not present in work item type definition
$nxEnumUnclassified. This distinction allows dashboards to highlight incomplete assessments.
LinkedHashMap Ordering
The returned$nxEnumCounts map preserves enum definition order from Polarion’s enumeration configuration. For example, ASIL enums are typically ordered [QM, A, B, C, D], so iteration yields counts in that sequence.
Performance Considerations
Scope Limitations
The macro cannot be called inside a#foreach loop with #set statements due to Velocity scoping. If you need to count multiple fields in sequence, call the macro once per field outside any loop context:
Related Macros
| Macro | Purpose | Link |
|---|---|---|
nxAPBuckets | Specialized enum counter for Action Priority (H/M/L) | nxAPBuckets |
nxLinkCoverage | Count items WITH links to target types (traceability) | nxLinkCoverage |
nxKpiCard | Render count values as styled KPI cards | nxKpiCard |
nxCoverageBar | Render percentage progress bar with traffic-light coloring | nxCoverageBar |
Common Field Names by Standard
ISO 26262 (Functional Safety):
classification— ASIL levels (qm, a, b, c, d)severity— S0-S3 (s0, s1, s2, s3)exposure— E0-E4 (e0, e1, e2, e3, e4)controllability— C0-C3 (c0, c1, c2, c3)
premitigationAP— Pre-mitigation action priority (h, m, l)postmitigationAP— Post-mitigation action priority (h, m, l)severity— Severity rating 1-10occurrence— Occurrence rating 1-10detection— Detection rating 1-10
risk— Risk level (low, medium, high, critical)likelihood— L1-L5harm— Harm severity
Troubleshooting
| Issue | Cause | Solution |
|---|---|---|
$nxEnumCounts is empty | Field name incorrect or field not on work items | Verify field exists via #get($item.fields().get($fieldName)) |
| All items counted as unclassified | Enum field returns null for all items | Check Polarion field configuration; ensure enum field is set on items |
| LinkedHashMap iteration shows wrong order | Using custom sort instead of Polarion definition | Remove custom sorting; preserve iteration order from macro return |
| Counts don’t add up to total | Unclassified items not included in $nxEnumCounts | Remember: $nxEnumTotal = $nxEnumCounts.values().sum() + $nxEnumUnclassified |
Macro Definition Location
Source:.polarion/pages/scripts/velocity/nextedy_solutions.vm
The nxCountByEnum macro is part of the Nextedy Solutions shared Velocity library and is automatically imported by all TestAuto2 — Automotive Safety Solution dashboards and reports.
For custom dashboard development, ensure the library is imported: