blokboard/ Open app

Node reference

Code

Transform data with custom JavaScript

CoreData

Code transforms data with JavaScript. The previous node’s output is available as input. Return the value you want the next node to receive.

Try it step by step#

  1. Add a Variable node with price set to 5 and quantity set to 2.
  2. Connect it to Code and paste the script below into JavaScript.
  3. Run once, inspect the input and result, then change quantity to 3 and run again.
const price = Number(input.price);
const quantity = Number(input.quantity);
return { total: price * quantity };

What to expect#

The first run returns {"total":10}; the second returns {"total":15}. The return statement is what sends the result to the next node.

Things to check#

  • Read input.price in JavaScript, not {{price}}. Double-brace expressions are not expanded inside code.
  • Return ordinary JSON data. Functions, circular objects, and non-finite numbers cannot be workflow results.
  • Use console.log() to inspect intermediate values. Use dedicated HTTP and file nodes for external work.

Keep learning#

Parameters#

SettingDefaultWhat it does
JavaScript(empty)Runs locally when the workflow reaches this node. Build a JSON-compatible result.

JavaScript: Double-brace expressions are not resolved in this field.

Inputs#

PortValueDescription
inanyIncoming value exposed to the script as input.

Outputs#

PortValueDescription
outanyThe JSON-compatible value returned by the script.