Formula errors in TestAuto2 risksheets typically fall into four categories: syntax errors, null field references, type mismatches, and circular dependencies. Use this diagnostic flowchart to identify your issue:
Step 1: Check Browser Console for Errors
Open your browser’s Developer Tools (F12 in Chrome/Edge, Cmd+Opt+I in Safari) and switch to the Console tab. Look for JavaScript errors related to formula evaluation:
Common error patterns:
Cannot read property 'KEY' of undefined → Field reference is null
Unexpected token → Syntax error in formula definition
Maximum call stack size exceeded → Circular reference between formulas
Risksheet formulas execute in the browser’s JavaScript runtime, not on the Polarion server. Always use browser DevTools Console to debug formula issues — server logs won’t capture these errors.
Edit the risksheet.json attachment in your risk specification document. Check that your formula follows valid JavaScript syntax:
{
"id": "asil",
"header": "ASIL",
"type": "enum:hara-asil",
"formula": "calcASIL",
"boldCol": true
}
Verify the formula function is defined in the formulas section:
"formulas": {
"calcASIL": "function(row) {\n var s = row.haraSeverity?.KEY || '';\n var e = row.haraExposure?.KEY || '';\n var c = row.haraControllability?.KEY || '';\n if (!s || !e || !c) return null;\n // ... matrix logic\n}"
}
Always use ?.KEY instead of .KEY when accessing enum fields in formulas: row.haraSeverity?.KEY. This prevents null reference errors when the field is empty.
Step 3: Handle Null and Missing Values
Most formula errors occur when custom fields are null or empty. Add defensive null checks:
Before (error-prone):
function(row) {
var severity = row.fmeaSeverity.KEY; // Crashes if null
var occurrence = row.fmeaOccurrence.KEY;
var detection = row.fmeaDetection.KEY;
return calculateAP(severity, occurrence, detection);
}
After (robust):
function(row) {
var s = row.fmeaSeverity?.KEY;
var o = row.fmeaOccurrence?.KEY;
var d = row.fmeaDetection?.KEY;
// Return null if any rating is missing
if (!s || !o || !d) return null;
return calculateAP(s, o, d);
}
Step 4: Fix Type Mismatches
Ensure formula return types match the column’s declared type:
| Column Type | Formula Must Return |
|---|
enum:action-priority | Enum ID string like 'ap-high' or 'ap-medium' |
text | String value (use .toString() if needed) |
number | Numeric value (use parseInt() or parseFloat()) |
itemLink | Work item reference object (not string ID) |
Example: Action Priority formula returning correct enum ID:
function calculateAP(s, o, d) {
var sNum = parseInt(s.replace('s', '')); // 's8' → 8
var oNum = parseInt(o.replace('o', ''));
var dNum = parseInt(d.replace('d', ''));
var product = sNum * oNum * dNum;
if (product >= 100) return 'ap-high';
if (product >= 40) return 'ap-medium';
return 'ap-low';
}
If your formula returns 'high' but the enum ID is actually 'ap-high', the cell will appear blank with no console error. Always verify enum IDs match your configuration exactly using the Polarion Administration → Enumerations panel.
Step 5: Check for Circular References
Circular dependencies between formulas cause infinite loops:
Solution: Redesign formulas so data flows in one direction. Use intermediate calculated columns if needed:
// BAD: Circular reference
"formulaA": "function(row) { return row.columnB * 2; }",
"formulaB": "function(row) { return row.columnA + 10; }"
// GOOD: One-way dependency
"baseValue": "function(row) { return row.inputField * 2; }",
"derivedValue": "function(row) { return row.baseValue + 10; }"
Replace your complex formula with a simple test to isolate the issue:
{
"id": "asil",
"formula": "function(row) { return 'test'; }"
}
If the test formula works but your full formula fails, gradually add back complexity until you identify the problematic line.
Step 7: Verify Field Bindings Match Custom Fields
Ensure field IDs in your formula match the actual custom field IDs in .polarion/tracker/fields/custom-fields.xml:
In risksheet.json:
{
"id": "haraSeverity",
"binding": "initialSeverity" // Must match custom field ID
}
In custom-fields.xml:
<field id="initialSeverity" type="enum"
dependency-id="hara-severity">
<label>Initial Severity</label>
</field>
Field ID matching is case-sensitive. haraSeverity ≠ HaraSeverity. Use the exact ID from custom-fields.xml in your formula’s row.fieldId references.
Step 8: Clear Browser Cache
Stale JavaScript from cached risksheet.json can cause formulas to fail after updates:
- Open your HARA or FMEA risksheet
- Press Ctrl+Shift+R (Windows/Linux) or Cmd+Shift+R (Mac) to force-reload
- Clear browser cache: Settings → Privacy → Clear browsing data → Cached files
- Close all Polarion tabs and re-login
ASIL Calculation (ISO 26262)
function calcASIL(row) {
var s = row.haraSeverity?.KEY || '';
var e = row.haraExposure?.KEY || '';
var c = row.haraControllability?.KEY || '';
if (!s || !e || !c) return null;
var sNum = parseInt(s.replace('s', '')); // 's3' → 3
var eNum = parseInt(e.replace('e', ''));
var cNum = parseInt(c.replace('c', ''));
// ISO 26262 3D matrix lookup
var matrix = {
's1': {/*...*/},
's2': {/*...*/},
's3': {/*...*/}
};
return matrix['s'+sNum]['e'+eNum][cNum-1];
}
Action Priority (AIAG-VDA FMEA)
function calcAP(row) {
var s = row.fmeaSeverity?.KEY;
var o = row.fmeaOccurrence?.KEY;
var d = row.fmeaDetection?.KEY;
if (!s || !o || !d) return null;
var severity = parseInt(s.replace('s', ''));
var occurrence = parseInt(o.replace('o', ''));
var detection = parseInt(d.replace('d', ''));
// High: S >= 8 OR (S >= 4 AND O >= 4 AND D >= 4)
if (severity >= 8) return 'ap-high';
if (severity >= 4 && occurrence >= 4 && detection >= 4) return 'ap-high';
if (severity * occurrence * detection >= 40) return 'ap-medium';
return 'ap-low';
}
Safety Goal ASIL Inheritance
function inheritASIL(row) {
// Safety Goal inherits ASIL from parent hazard
var parentHazard = row.derivedFrom; // Link to hazard
return parentHazard?.asil || null;
}
Verification
You should now see:
- ✅ Formula columns displaying calculated values (ASIL, Action Priority, etc.)
- ✅ No
#ERROR markers in cells
- ✅ Browser console free of JavaScript errors
- ✅ Formula recalculates immediately when input fields change
If formulas still fail after these steps, export your risksheet.json and validate it with a JSON linter to check for structural issues.
See Also