Decision icon

Decision

Decision Node

Overview

The Decision node is designed to evaluate a set of user-defined rules against incoming data and apply a specified "hit policy" to determine the output. This node is useful in scenarios where you need to make decisions based on multiple conditions, such as filtering, aggregating, or selecting specific items from your data.

Practical examples:

  • Selecting the first item that matches certain criteria.
  • Counting how many items meet a condition.
  • Finding the maximum or minimum value among items that satisfy a rule.
  • Summing up values for all items that match a condition.

Properties

Name Type Meaning
Rule String The name of the rule set being evaluated. Useful for documentation or identification.
Hit Policy Options Determines how matching rules are processed:
- Count: Number of items meeting the condition
- First: First item that meets the condition
- Max: Item with the maximum result value
- Min: Item with the minimum result value
- Sum: Sum of result values for matching items
Rules FixedCollection (multiple) A list of rule items, each containing:
- Condition (Boolean): Whether the rule applies.
- Result (String): Value associated with this rule.
- Description (String): Description for this rule.

Output

The node outputs an array of objects, each with the following structure:

{
  "operation": "<selected hit policy>",
  "value": <result according to hit policy>,
  "results": [
    {
      "condition": <boolean>,
      "result": <string>,
      "description": <string>
    },
    ...
  ],
  "item": { ... } // Original input item's json
}
  • operation: The selected hit policy (e.g., "count", "first", "max", "min", "sum").
  • value: The computed result based on the hit policy.
  • results: The list of rule items evaluated for this input.
  • item: The original input item's JSON data.

Note: The node does not output binary data.

Dependencies

  • No external services or API keys required.
  • No special n8n configuration or environment variables needed.

Troubleshooting

Common issues:

  • Incorrect rule configuration: If the rules are not set up correctly (e.g., missing conditions or results), the output may be empty or not as expected.
  • Type mismatches: For "max", "min", or "sum" policies, ensure that the "Result" field contains numeric values; otherwise, calculations may fail or produce unexpected results.
  • Empty input: If no input data is provided, the node will return an empty array.

Error messages:

  • Errors related to missing or invalid parameters will typically reference the property name (e.g., "rules.item") and the index of the problematic item.
  • If a non-numeric value is used with "max", "min", or "sum", the result may be NaN or undefined.

How to resolve:

  • Double-check that all rules have valid conditions and result values.
  • Ensure that numeric operations use numeric result fields.
  • Review the node's configuration if output is not as expected.

Links and References

Discussion