Skip to content

Functions

A function template groups reusable JavaScript functions with declared inputs, outputs, and test cases. Publish the template so multiple workflows can call their functions from Code nodes.

Use case Example
Normalize identifiers Trim and uppercase a supplier number before a lookup.
Transform records Map order rows to a common response shape for several workflows.
Calculate a value Convert minutes to hours using the same rounding rule in each caller.

Create and test a function template

  1. Open Resources → Functions and select Add.
  2. In Function Template Builder, enter the template Name and Description and review Code.
  3. Select Add to create a function. Name the function and describe what it does. In Code, enter its JavaScript implementation. Review any code produced using Optimize before publishing.
  4. In Input, declare the names, types, and descriptions of the arguments. In Output, configure the return type or structured result.
  5. Open Test Cases and validate representative inputs and boundary cases. You can also use the function's Quick test action to inspect an individual result.
  6. Select Publish to make the template available to workflows. Use Save and Close to keep a draft.

Supplier number normalization example

Create a Supplier Utilities template. Add a function named normalizeSupplierNumber with one String input named supplierNumber and a String return. Use this implementation.

function normalizeSupplierNumber(supplierNumber) {
  return (supplierNumber ?? "").trim().toUpperCase();
}

Test {"supplierNumber":" sup-1042 "} and expect "SUP-1042". Test a blank value and expect an empty string.

In a workflow, add a Code node and set Source to Reusable Functions. Select the published template and normalizeSupplierNumber. Map supplierNumber to {{$context.$triggers.REST.$input.supplierNumber}} if the workflow accepts it as a webhook input. Use Debug to confirm the output structure, then map the normalized number into the supplier lookup. Route an empty result to input handling before making the lookup.

See Code node configuration and Normalize a supplier number for the workflow pattern.