Return from Function

Return a value from a Function node

Overview

The Return from Function node is designed to return a value from within a custom Function node execution in n8n workflows. It allows users to write JavaScript code that determines the output value dynamically based on the input data and context. This node is particularly useful when you want to finalize or transform data inside a function call and send back a specific result.

Typical use cases include:

  • Returning processed data after complex calculations or transformations.
  • Sending back status or metadata from a function execution.
  • Integrating with asynchronous function calls where the return value needs to be explicitly set and communicated.

For example, you might use this node to return a message object with a timestamp after processing input JSON data.

Properties

Name Meaning
Return Code JavaScript code snippet that defines what the node returns. You write code using variables like $json (current item JSON), $binary (binary data), $index (item index), and $item (full item). The code must end with a return statement specifying the output. Example options: any valid JS expression returning an object, string, number, etc.

Output

The node outputs an array of items, each containing:

  • json: The returned JSON object as defined by the executed return code, cleaned of internal _functionCall metadata.
  • index: The index of the item in the input array.
  • binary: Any binary data passed through unchanged.

This output represents the final return values from the function call, ready for further workflow processing.

Dependencies

  • Requires integration with a function registry system that manages function calls and responses.
  • Uses an API or service (likely Redis streams) if queue mode is enabled to publish responses asynchronously.
  • Needs proper configuration of the function registry environment and possibly Redis or other messaging infrastructure for queue mode.
  • Relies on an API key or authentication token implicitly managed by the function registry system (not exposed here).

Troubleshooting

  • Error: "ReturnFromFunction must be used within a Function that was called via CallFunction"
    This error occurs if the node is used outside the expected function call context. Ensure it is placed only inside workflows triggered by a function call node.

  • Code execution errors in the Return Code
    If your JavaScript code has syntax errors or runtime exceptions, the node will throw an error indicating the failure. Check your code carefully and use the provided logging to debug.

  • Failed to publish response / resolve return value
    When queue mode is enabled, network or configuration issues with the messaging system can cause failures. Verify connectivity and credentials for the underlying message broker or Redis instance.

  • Timeouts or missing responses
    If the function call does not receive a timely response, ensure the Return from Function node executes correctly and publishes the response. Check logs for any suppressed errors.

Links and References


This summary is based solely on static analysis of the provided source code and property definitions.

Discussion