You are here:
Guidelines for Writing a Formula
A KPI definition’s formula, which is JavaScript, is validated to prevent the use of code that can impact the security and stability of the system.
Here’s an example of a formula.
(ProLEGrossRevenue,ProLETotalPromoSpend,ProLENonPromoSpend) => {return ProLEGrossRevenue - ProLETotalPromoSpend - ProLENonPromoSpend;}
Follow these rules when you add a KPI definition formula.
General Rules
Don’t use these terms in a KPI definition formula:
- config
- console
- context
- _dirname
- exports
- _filename
- logger
- module
- process
- require
- util
In the KPI definition formula, Math, calcHelper, and CalcErrors act as read-only global variables.
JavaScript Rules
| RuleID | Description |
|---|---|
| Possible Errors | |
| no-compare-neg-zero | Comparing against negative zero isn’t allowed |
| no-cond-assign | An assignment operator in a conditional expression isn’t allowed |
| no-console | Use of console objects isn’t allowed |
| no-constant-condition | Constant expressions in conditions aren’t allowed |
| no-control-regex | Control characters in regular expressions aren’t allowed |
| no-debugger | Debugger isn’t allowed |
| no-dupe-args | Duplicate arguments in function definitions aren’t allowed |
| no-dupe-keys | Duplicate keys in object literals aren’t allowed |
| no-duplicate-case | Duplicate case labels aren’t allowed |
| no-empty | Empty block statements aren’t allowed |
| no-empty-character-class | Empty character classes in regular expressions aren’t allowed |
| no-ex-assign | Reassigning exceptions in catch clauses isn’t allowed |
| no-extra-semi | Unnecessary semicolons aren’t allowed |
| no-func-assign | Reassigning function declarations isn’t allowed |
| no-function-to-variable | Assigning functions to variables isn’t allowed |
| no-inner-declarations | Variable or function declarations in nested blocks aren’t allowed |
| no-invalid-regexp | Invalid regular expression strings in RegExp constructors aren’t allowed |
| no-obj-calls | Calling global object properties as functions isn’t allowed |
| no-regex-spaces | Multiple spaces in regular expressions aren’t allowed |
| no-sparse-arrays | Sparse arrays aren’t allowed |
| no-unexpected-multiline | Confusing multiple line expressions isn’t allowed |
| no-unreachable | Unreachable code after return, throw, continue, and break statements isn’t allowed |
| no-unsafe-finally | Control flow statements in the final blocks aren’t allowed |
| no-unsafe-negation | Negating the left operand of relational operators isn’t allowed |
| use-isnan | Require calls to isNaN() when checking for NaN |
| valid-typeof | Enforce comparing type of expressions against valid strings |
| Best Practices | |
| no-case-declarations | Lexical declarations in case clauses aren’t allowed |
| no-empty-pattern | Empty destructuring patterns aren’t allowed |
| no-fallthrough | Fall through of case statements isn’t allowed |
| no-global-assign | Assignments to native objects or read-only global variables aren’t allowed |
| no-octal | Octal literals aren’t allowed |
| no-redeclare | Variable redeclaration isn’t allowed |
| no-self-assign | Assignments where both sides are the same isn’t allowed |
| no-unused-labels | Unused labels aren’t allowed |
| no-useless-escape | Unnecessary escape characters aren’t allowed |
| Variables | |
| no-delete-var | Deleting variables isn’t allowed |
| no-undef | Use of undeclared variables unless mentioned in global comments isn’t allowed |
| no-unused-vars | Unused variables aren’t allowed |
| Other | |
| constructor-super | Require super calls in constructors |
| no-class-assign | Reassigning class members isn’t allowed |
| no-const-assign | Reassigning const variables isn’t allowed |
| no-dupe-class-members | Duplicate class members aren’t allowed |
| no-new-symbol | New operators with the Symbol object aren’t allowed |
| no-this-before-super | this before calling super() in constructors isn’t
allowed |
| require-yield | Require generator functions to contain yield |
| Security | |
| no-while-loops | while loops aren’t allowed |
| no-do-while-loops | do...while loops aren’t allowed |
| no-for-loop | For...in loops aren’t allowed |
| no-accessing-globals | Accessing globals isn’t allowed |
| no-eval | Usage of any statement that is used to define or execute new functions isn’t allowed |
| no-extend | Extending native JavaScript objects isn’t allowed |
for-of to iterate
over arrays and for-in to iterate over objects.- Other KPIs References In a Formula
Specify other KPIs as an input parameter in a formula. The other KPIs that are used as the input parameter can be of either the same or a different time granularity. You can also reference the total value of a KPI with a different granularity. - Calculation Helper Functions In a Formula
In general, a formula for calculating a KPI can access only the parameters specified in the formula. However, a formula can access a calculation helper without specifying the helper as an input parameter. - Referencing Variables
Depending on the scope of a KPI, you can reference a promotion or a tactic variable in a formula.

