Skip to main content

Function Declaration and Execution Context

Formulas are JavaScript functions defined in the formulas object within your risksheet.json configuration. Each formula receives an info parameter containing the execution context:
PropertyTypeDescription
info.itemobjectComplete work item data with all column bindings as key-value pairs
info.valueanyCurrent cell value (for display-time formulas)
info.cellHTMLElementDOM element of the cell being rendered
info.rownumberZero-based row index in the grid
info.gridFlexGridReference to the Wijmo FlexGrid control
// Example formula structure
formulas.myFormula = function(info) {
  // Access other columns via info.item
  var occ = info.item['occurrence'];
  var sev = info.item['severity'];
  var det = info.item['detection'];
  
  // Perform calculation
  var result = occ * sev * det;
  
  // Return null for empty calculations to avoid displaying 0
  return result ? result : null;
}

Built-in Function Categories

Arithmetic Operations

Perform mathematical calculations on numeric columns.
FunctionOperatorsExampleResult
Addition+info.item['cost'] + 100Sum of values
Subtraction-info.item['original'] - info.item['reduction']Difference
Multiplication*info.item['occ'] * info.item['sev']Product
Division/info.item['total'] / info.item['count']Quotient
Modulo%info.item['value'] % 2Remainder
PowerMath.pow()Math.pow(info.item['base'], 2)Exponent

Comparison Operators

Compare values to make conditional decisions in formulas.
OperatorUsageReturnsExample
==Equalitybooleaninfo.item['status'] == 'Active'
!=Inequalitybooleaninfo.item['priority'] != 'Low'
>Greater thanbooleaninfo.item['rpn'] > 200
<Less thanbooleaninfo.item['cost'] < 5000
>=Greater or equalbooleaninfo.item['sev'] >= 8
<=Less or equalbooleaninfo.item['occ'] <= 3

Ternary Conditional

Return different values based on conditions.
// Syntax: condition ? trueValue : falseValue
formulas.riskLevel = function(info) {
  var rpn = info.item['rpn'];
  return rpn > 350 ? 'High' : (rpn > 150 ? 'Medium' : 'Low');
}

Logical Operators

Combine multiple conditions in formula logic.
OperatorUsageExample
&& (AND)Both conditions trueinfo.item['sev'] > 7 && info.item['occ'] > 5
|| (OR)Either condition trueinfo.item['status'] == 'Open' || info.item['overdue'] == true
! (NOT)Negates condition!info.item['resolved']

Risk Priority Number (RPN) Calculation

The most common FMEA formula multiplies three severity metrics to calculate risk priority:
// Initial RPN - before mitigations
formulas.commonRpn = function(info) {
  var value = info.item['occ'] * info.item['det'] * info.item['sev'];
  return value ? value : null;
}

// Revised RPN - after mitigations applied
formulas.commonRpnNew = function(info) {
  var value = info.item['occNew'] * info.item['detNew'] * info.item['sevNew'];
  return value ? value : null;
}
Always return null for empty calculations instead of 0 or empty string. This prevents displaying misleading zero values and maintains clean visual formatting in your grid.

String and Array Functions

String Operations

FunctionPurposeExample
.toUpperCase()Convert to uppercaseinfo.item['title'].toUpperCase()
.toLowerCase()Convert to lowercaseinfo.item['category'].toLowerCase()
.substring()Extract substringinfo.item['id'].substring(0, 5)
.indexOf()Find positioninfo.item['description'].indexOf('error')
.split()Split into arrayinfo.item['tags'].split(',')

Array Operations

FunctionPurposeExample
.lengthGet array sizeinfo.item['tasks'].length
.includes()Check if containsinfo.item['status'].includes('Review')
.filter()Filter elementsinfo.item['items'].filter(x => x.active)
.map()Transform elementsinfo.item['numbers'].map(x => x * 2)
.join()Combine to stringinfo.item['labels'].join(', ')

Mathematical Functions

Access JavaScript’s Math object for advanced calculations:
FunctionPurposeExample
Math.round()Round to nearest integerMath.round(info.item['average'])
Math.floor()Round downMath.floor(info.item['value'])
Math.ceil()Round upMath.ceil(info.item['value'])
Math.abs()Absolute valueMath.abs(info.item['variance'])
Math.min()Minimum valueMath.min(a, b, c)
Math.max()Maximum valueMath.max(info.item['scores'])
Math.sqrt()Square rootMath.sqrt(info.item['variance'])

Formula Execution Flow

diagram

Formula Configuration Reference

PropertyTypeRequiredDescription
formulastringYesFunction name to call from the formulas object (e.g., 'commonRpn')
typestringNoColumn data type; formula columns auto-detect as their result type
readOnlybooleanNoFormula columns are read-only by default; set explicitly to allow editing
bindingstringNoColumn binding path; auto-generated from column ID if not specified
headerstringYesDisplay name for the calculated column
widthnumberNoColumn width in pixels

Type Coercion in Formulas

JavaScript automatically coerces types in formula expressions:
OperationInput TypesResult TypeExample
Arithmeticnumber + numbernumber5 + 3 = 8
String Concatenationstring + anystring'Value: ' + 42 = 'Value: 42'
Comparisonany == anyboolean'5' == 5 = true
Logicalany && anyboolean0 && true = false
Ensure numeric columns contain valid numbers. Empty strings, undefined, or non-numeric values in arithmetic operations return NaN. Use conditional checks to validate data before calculations.

Performance Considerations

Formulas execute for every cell in every row during grid rendering. Optimize performance by:
  • Avoiding complex nested calculations when simple arithmetic suffices
  • Using early returns to exit calculations when intermediate results are null
  • Limiting array operations (filter, map) to small datasets
  • Caching frequently computed values using hidden columns
  • Minimizing DOM manipulation (accessing info.cell) in hot-path formulas

Common Patterns

Weighted Scoring

formulas.weightedScore = function(info) {
  var w1 = info.item['metric1'] * 0.5;
  var w2 = info.item['metric2'] * 0.3;
  var w3 = info.item['metric3'] * 0.2;
  return w1 + w2 + w3;
}

Conditional Escalation

formulas.escalationLevel = function(info) {
  if (info.item['severity'] >= 8 && info.item['duration'] > 30) {
    return 'Critical';
  } else if (info.item['severity'] >= 6 || info.item['impact'] == 'Major') {
    return 'High';
  }
  return 'Normal';
}

See Also

Source Code
  • AppConfig.ts
  • risksheet.json
  • AppConfigHelper.ts
  • CellPreviewFormatter.ts
  • PolarionAppConfigManager.java