Table of Contents

Formulas JavaScript V2 Specs 🆕 v16

V2 formulas are a major enhancement to v1 formulas. Improvements include:

  1. Intellisense while typing the formula using VS Code

  2. Promise support

  3. Ability to stop the formula from running

  4. Ability to set other fields from a formula

  5. Ability to add Comments before the formula

  6. Ability to get App Settings in your formula

  7. Ability to return Validation on a field

V2 Function Specs

// new formula syntax - see https://go.2sxc.org/formulas
v2((data, context) => {
  return data.value;
});
  1. All functions must be called v2, it must be lower case
    This is important because when APIs change, we will use v3, etc.

  2. The first line in the code must start with the function name v2.
    You can put comments or empty lines before the v2, but they must always use // and not /* */

  3. The v2(...) function takes 1 parameter, namely the function to execute. This is different from v1.

  4. The reason we need an inner function is so that VS Code can provide intellisense while you type.

  5. Your function must look like one of these

    • v2(() => { ... });
    • v2((data) => { ... });
    • v2((data, context) => { ... });
  6. The parameter names are anything you want, but the order of what you get is always data and then context. You can also write

    • v2((d, c) => { ... });

V2 data and context Objects

👉🏼 See data

👉🏼 See context

V2 Returned Values

👉🏼 See Return Values

Tips and Tricks

  1. You can always add a console.log(data, context); or similar in your code to see in real time what's being processed.
  2. You can also add a line debugger; and the browser will stop at this line so you can inspect the variables and watch your code.
  3. For now, we strongly recommend to use Formulas as pure functions, but with experience the recommendation may change.

History

  • Introduced in 2sxc 12.01
  • Added data.parameters in v13.10
  • Added context.features, context.app, context.user, context.sxc etc. in v13.10
  • Massively improved in v2 in 2sxc 16.00