Menu icon

Menu

Displays the Pre-configured menu items

Overview

This node, named "Menu," is designed to present a pre-configured menu structure within an n8n workflow. It allows users to define menu items, branching rules, and input validation, enabling interactive decision trees or guided workflows. The node supports running custom JavaScript or Python code either once for all input items or individually per item, providing flexibility in processing logic.

Common scenarios where this node is beneficial include:

  • Creating conversational menus or decision trees in chatbots.
  • Guiding users through multi-step forms or surveys with branching logic.
  • Implementing dynamic menu-driven workflows that adapt based on user input or other conditions.

For example, you could use this node to display a menu asking users to select from several options, validate their input against a regular expression, and branch the workflow accordingly.

Properties

Name Meaning
Path Defines whether this is the natural path of the tree ("Main") or a branch ("Branch").
Node Name Short descriptive name of the menu node.
Node Type Type of the node, typically "MENU" indicating a list of numbered options for user selection.
Validation Failure Text Text displayed if the user enters an invalid value according to the validation rule.
Menu Introduction Text Introduction text shown to users when the menu is presented; guides them to select an option.
Input VariableName Name of the input variable expected from the user.
Input Validation Regular expression string used to validate the user's input.
Node Status Indicates whether the node is active, inactive, or in test mode. Options: Active, Inactive, Test.
Level Numeric level indicator (usage context-dependent).
Variables (formFields) Collection of variables defining form fields, each with a name, type (String, Number, JSONArray, JSONObject), and a default value.
Choose Processor Specifies processors to execute at different stages: Pre Processor, Input Processor, Post Processor (each accepts a string value representing processor logic).
Mode Determines execution mode of embedded code: "Run Once for All Items" or "Run Once for Each Item".
Language Programming language for the embedded code: JavaScript or Python (Beta).
JavaScript The actual JavaScript code to execute within the node. Supports special variables like $today for dates and $jmespath for JSON querying.
Skip Rule Rule expression to conditionally skip this node during execution.
Branching Rule Rules defining how to branch the workflow, supporting multiple branching rules either by node or text branches.
Flags Collection of boolean flags controlling behavior: Sanitize input, Encrypt input, Mark as Last Node, Close Session flag, Publish output flag.

Output

The node outputs an array of items, each containing a json field with the processed data. The structure of the json output depends on the executed code and input data but generally includes:

  • The results of the custom JavaScript or Python code execution.
  • Standardized output after processing.
  • If errors occur during code execution, an error message is included in the json.error field.
  • Binary data can also be outputted if produced by the code, though this is optional and context-dependent.

The output respects the execution mode:

  • For "Run Once for All Items," a single output item is returned.
  • For "Run Once for Each Item," one output item per input item is returned, preserving pairing information.

Dependencies

  • The node relies on an internal sandbox environment to safely execute user-provided JavaScript or Python code.
  • It uses lodash's set function for object manipulation.
  • Environment variable CODE_ENABLE_STDOUT controls whether console logs are output during manual runs.
  • No external API keys or services are required by default, but user code may introduce dependencies.
  • The node requires proper configuration of input properties and valid code snippets to function correctly.

Troubleshooting

  • Code Execution Errors: If the embedded JavaScript or Python code contains syntax errors or runtime exceptions, the node will throw errors unless "Continue On Fail" is enabled. Error messages will appear in the output under json.error.
  • Validation Failures: If user input does not match the provided regular expression, the node displays the configured validation failure text.
  • Incorrect Branching: Misconfigured branching rules may cause unexpected workflow paths. Verify branching expressions carefully.
  • Empty or Missing Inputs: Ensure that required inputs such as "Node Name," "Menu Introduction Text," and "Variables" are properly set.
  • Console Logs Not Visible: Console output during manual runs depends on the environment variable CODE_ENABLE_STDOUT. Set it to "true" to enable logging.
  • Mode Mismatch: Selecting an inappropriate mode (e.g., running code once for all items when per-item processing is needed) may lead to incorrect results.

Links and References

Discussion