Zie619/n8n-workflows · error · Error

Approved quantity must be greater than 0

Error message

Approved quantity must be greater than 0

What it means

This error is thrown by a custom n8n Code node ('Verify Approval Data') that validates an approval form submission before it is written back to Google Sheets. The workflow expects an 'Approved Quantity' field that is a positive number whenever 'Action' equals 'approve'. If the field is missing, undefined, a non-numeric string (which makes '<= 0' coerce unexpectedly), zero, or negative, the guard fires and halts the branch.

Source

Thrown at workflows/Code/0926_Code_Webhook_Create_Webhook.json:1703

              "type": "string",
              "value": "={{ new Date().toISOString() }}"
            }
          ]
        }
      },
      "typeVersion": 3.4,
      "notes": "This set node performs automated tasks as part of the workflow."
    },
    {
      "id": "6749923b-1032-4adb-b805-eda6efd5ee1c",
      "name": "Verify Approval Data",
      "type": "n8n-nodes-base.code",
      "position": [
        6340,
        4060
      ],
      "parameters": {
        "jsCode": "const input = $input.all()[0].json;\nif (!input[\"Submission ID\"]) throw new Error(\"Submission ID is missing\");\nif (![\"approve\", \"reject\"].includes(input[\"Action\"])) throw new Error(\"Invalid action\");\nif (input[\"Action\"] === \"approve\" && input[\"Approved Quantity\"] <= 0) throw new Error(\"Approved quantity must be greater than 0\");\nreturn { json: input };"
      },
      "typeVersion": 2,
      "notes": "This code node performs automated tasks as part of the workflow."
    },
    {
      "id": "c5e34da4-81ec-47dc-aacf-4d6e0cf4256c",
      "name": "Retrieve Issue Request Details",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        6560,
        3840
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ $json[\"Submission ID\"] }}",

View on GitHub (pinned to 94007c1445)

Solutions

  1. Ensure the approval form always submits a positive number for Approved Quantity when Action=approve (make the field required and numeric in the form/Sheet).
  2. Coerce and validate explicitly before the comparison: use Number(input['Approved Quantity']) and validate Number.isFinite(n) && n > 0 so blank strings and garbage fail loudly with a clearer message.
  3. Check the upstream Set/Form node field names match exactly ('Approved Quantity' with that casing and spacing); log $input.all()[0].json to verify payload shape.
  4. If zero-quantity approvals are legitimate in your process, change the business rule instead of the data.

Example fix

// before
if (input["Action"] === "approve" && input["Approved Quantity"] <= 0) throw new Error("Approved quantity must be greater than 0");

// after
if (input["Action"] === "approve") {
  const qty = Number(input["Approved Quantity"]);
  if (!Number.isFinite(qty) || qty <= 0) {
    throw new Error(`Approved Quantity must be a number > 0, got: ${JSON.stringify(input["Approved Quantity"])}`);
  }
}
Defensive patterns

Strategy: validation

Validate before calling

// In the Code node, before the throw:
const qty = Number(input["Approved Quantity"]);
const action = String(input["Action"] || '').toLowerCase();
const isValid = action === 'reject' || (action === 'approve' && Number.isFinite(qty) && qty > 0);
// route invalid payloads to an error/notification branch instead of throwing

Type guard

function isValidApproval(p) {
  return Boolean(p && p["Submission ID"] &&
    ["approve", "reject"].includes(p["Action"]) &&
    (p["Action"] !== "approve" || (Number.isFinite(Number(p["Approved Quantity"])) && Number(p["Approved Quantity"]) > 0)));
}

Try / catch

try {
  if (!isValidApproval(input)) return [{ json: { invalidPayload: input } }]; // to error branch
  return { json: input };
} catch (e) {
  throw new Error(`Approval validation failed: ${e.message}`);
}

Prevention

When it happens

Trigger: A webhook/form submission arrives with Action='approve' but Approved Quantity is 0, empty string, undefined, or negative; or the field arrives as a string like '5' compared with <= 0 still passing but '' <= 0 evaluating true (empty string coerces to 0), so blank form inputs are the most common trigger. Renaming the form field ('Approved Qty', 'approved_quantity') also produces undefined <= 0 === false, but empty/zero values produce true.

Common situations: Google Form or n8n Form trigger where the quantity question was optional or skipped; a Sheets-driven approval UI where the approver left the cell blank; field-name drift between the form definition and the Code node; string vs number type mismatch from form payloads.

Related errors


AI-assisted analysis of Zie619/n8n-workflows@94007c1445 (2026-08-15). Data as JSON: /api/errors/acf9435359530822. Report an issue: GitHub.