Skip to main content
The Functions node executes reusable JavaScript functions within your workflows. Instead of writing the same code in multiple Custom Code nodes, create functions once and call them across any workflow. Functions can be organization-specific custom functions you create, or pre-defined library functions provided by Refold.

When to use

  • Execute reusable logic across multiple workflows without duplicating code
  • Find specific elements in arrays from API responses
  • Group data by key values for organization and reporting
  • Encrypt sensitive data before sending to external systems
  • Convert data formats (EDI, X12, cXML) for enterprise integrations
  • Perform common operations without writing custom code each time
Functions are organization-specific. Create and manage functions under More > Functions in your dashboard.

Input parameters

Select internal function
dropdown
required
Choose the function to execute from your organization’s Functions Library. Functions are created and managed in More > Functions. After selecting a function, input fields are dynamically generated based on the function’s parameter requirements.
Custom Output
dynamic fields
Map function output to custom field names. Click + Add Field to define additional output fields that will be included in the node’s response alongside the function result.

Dynamic input fields

When you select a function, input fields are automatically generated based on that function’s parameters. For example, selecting “Find element in array” displays:
FieldDescription
arrayThe array to search through
elementThe element to find
Refer to the function’s code in More > Functions to understand which parameters are required and which are optional.

Pre-defined library functions

Refold provides several pre-defined library functions that are available by default. These functions cannot be edited but can be used immediately in any workflow.
FunctionParametersDescription
Find element in arrayarray, elementSearches through an array to locate a specific element. Returns the index of the element, or -1 if not found.
Group objects by a keyarray, keyGroups an array of objects by a specified key field. Returns an object with grouped arrays.
FunctionParametersDescription
Encrypt a stringstring, passwordEncrypts sensitive text data and returns the encrypted string. Provide an optional password to key the encryption.
FunctionParametersDescription
Get current dateformatRetrieves the current date and time in the requested format. Useful for timestamping records or calculating relative dates.
Convert date from one format to anotherdate, from_format, to_formatTransforms a date between format patterns. Supports patterns such as yyyy-MM-dd, MM/dd/yyyy, dd-MM-yyyy, dd MMM yyyy, and date-time patterns like yyyy-MM-dd'T'HH:mm:ssXXX and hh:mm a.
Extract date unitsdateParses a date to extract components like year, month, day, and hour. Accepts ISO, time-zone, JS, timestamp, and date-only formats.
Add/Subtract timedate, amount, unitAdds or subtracts time from an ISO date. Supported units: seconds, minutes, hours, days, weeks, months, years.
FunctionParametersDescription
Generate UUIDnoneCreates unique identifiers (UUIDs) for tracking, record linking, or external system integration.
FunctionParametersDescription
Math Operationsnumbers, operationPerforms sequential arithmetic on a list of numbers. Supported operations: add, subtract, multiply, divide, modulus.
Your organization may have additional custom functions created for specific use cases. Check More > Functions to see all available functions.

Creating custom functions

Create reusable functions for your organization that can be called from any workflow.
1

Navigate to Functions

In the Refold dashboard, go to More > Functions.
2

Create a new function

Click + Create Function and provide a name for your function.
3

Write your function

Define your function code, input parameters, and output fields. You can use supported JavaScript libraries in your function code.
4

Save the function

Click Create to save. The function is now available in the Functions node dropdown across all workflows.

Supported JavaScript libraries

The following npm modules can be used in your custom function code:
LibraryDescription
axiosHTTP client for API requests
cheerioHTML parsing and manipulation
date-fnsDate utility functions
fast-xml-parserXML parsing and building
fuse.jsFuzzy search library
lodashUtility functions for arrays, objects, strings
mimeMIME type detection
number-to-wordsNumber to text conversion
urlURL parsing utilities
uuidUUID generation
danfoData analysis and manipulation
Need a library that’s not listed? Contact support to request additional libraries.

Library usage examples

    const axios = require('axios');

    async function yourFunction(params) {
      const res = await axios.get("https://api.example.com/data");
      return {
        data: res.data
      }
    }
    const _ = require('lodash');

    function yourFunction(params) {
      const array = [{ id: 3 }, { id: 1 }, { id: 2 }];
      const sortedData = _.sortBy(array, "id");
      return {
        data: sortedData
      };
    }
    const dfd = require('dfd');

    function yourFunction(params) {
      const s = new dfd.Series([1, 3, 5, undefined, 6, 8]);
      return dfd.toJSON(s);
    }

Output

The output structure depends on the function being executed. Each function returns its result in the body field.
    {
      "status": "Success",
      "node_id": "8",
      "node_name": "Functions",
      "body": {
        "index": 1
      }
    }
    {
      "status": "Success",
      "node_id": "8",
      "node_name": "Functions",
      "body": {
        "index": -1
      }
    }
    {
      "status": "Success",
      "node_id": "8",
      "node_name": "Functions",
      "body": {
        "result": "your_function_output",
        "custom_field": "mapped_value"
      }
    }
    {
      "status": "Errored",
      "node_id": "8",
      "node_name": "Functions",
      "body": "Function execution failed: undefined is not a function"
    }

Adding to your workflow

1

Add the Functions node

In the workflow editor, click Add Node and select Functions from the utility nodes section.
2

Select a function

Choose a function from the Select internal function dropdown. This list includes pre-defined library functions and any custom functions created in your organization.
3

Configure input parameters

Fill in the dynamically generated input fields based on the selected function’s requirements. Use dynamic variables from previous nodes where needed.
4

Configure custom output (optional)

Click + Add Field under Custom Output to map function results to custom field names for use in subsequent nodes.
5

Test the node

Click the Run tab to execute and verify the function returns the expected output.

Examples

Search for a specific vendor in an array returned from an SAP API call.Function: Find element in array
FieldValue
array{{sap_get_vendors.body.vendors}}
element{{webhook.vendor_id}}
Output:
    {
      "status": "Success",
      "node_id": "8",
      "node_name": "Functions",
      "body": {
        "index": 3
      }
    }
Use Case: Use the returned index with a Rule node to check if the vendor exists (index >= 0) before proceeding with updates.
Organize NetSuite invoices by their payment status for processing.Function: Group objects by a key
FieldValue
array{{netsuite_get_invoices.body.invoices}}
keypayment_status
Output:
    {
      "status": "Success",
      "node_id": "8",
      "node_name": "Functions",
      "body": {
        "paid": [
          {"id": "INV-001", "payment_status": "paid", "amount": 1500},
          {"id": "INV-003", "payment_status": "paid", "amount": 2200}
        ],
        "pending": [
          {"id": "INV-002", "payment_status": "pending", "amount": 3000}
        ],
        "overdue": [
          {"id": "INV-004", "payment_status": "overdue", "amount": 750}
        ]
      }
    }
Use Case: Process each status group differently, such as sending reminders for pending invoices or escalations for overdue ones.
Encrypt vendor bank account information before storing or transmitting.Function: Encrypt a string
FieldValue
string{{vendor.bank_account_number}}
Output:
    {
      "status": "Success",
      "node_id": "8",
      "node_name": "Functions",
      "body": {
        "encrypted": "aGVsbG8gd29ybGQ=..."
      }
    }
Use Case: Encrypt PII or financial data before sending to external systems or storing in logs.
Transform a JSON purchase order into EDI X12 format for transmission to trading partners.Function: Convert JSON to X12 EDI string (custom function)
FieldValue
jsonData{{purchase_order}}
transaction_type850
Output:
    {
      "status": "Success",
      "node_id": "8",
      "node_name": "Functions",
      "body": {
        "edi_string": "ISA*00*          *00*          *ZZ*SENDER         *ZZ*RECEIVER       *...",
        "transaction_type": "850"
      }
    }
Use Case: Generate EDI documents for B2B transactions with trading partners who require X12 format.

Troubleshooting

ProblemSolution
Function not in dropdownVerify the function exists in More > Functions. Check if it was created in the correct organization.
Function was deletedRecreate the function or select an alternative function. Workflows using deleted functions will fail.
ProblemSolution
”undefined is not a function”Check the function code for syntax errors. Verify all required libraries are imported correctly.
Function returns unexpected outputReview the function’s input parameters and ensure values are passed correctly. Check the function code logic.
Timeout errorsOptimize the function code. Avoid long-running operations or external API calls with slow response times.
ProblemSolution
Required parameter missingRefer to the function code in More > Functions to identify required parameters.
Invalid data typeEnsure input values match expected types (string, array, object). Use a Custom Code node to transform data if needed.
Dynamic variable not resolvingVerify the source node has executed successfully and the variable path is correct.
Use the Custom Code node for one-off logic that doesn’t need to be reused. Reserve functions for code that will be used across multiple workflows.

Next steps

Custom Code node

Write one-off custom logic.

Rule node

Add conditional logic based on function output.

Loop node

Iterate over grouped data from functions.

Transform node

Run JSONata-based data transformation.