{"record":{"id":"acf9435359530822","repo":"Zie619/n8n-workflows","slug":"approved-quantity-must-be-greater-than-0","errorCode":null,"errorMessage":"Approved quantity must be greater than 0","messagePattern":"Approved quantity must be greater than 0","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"workflows/Code/0926_Code_Webhook_Create_Webhook.json","lineNumber":1703,"sourceCode":"              \"type\": \"string\",\n              \"value\": \"={{ new Date().toISOString() }}\"\n            }\n          ]\n        }\n      },\n      \"typeVersion\": 3.4,\n      \"notes\": \"This set node performs automated tasks as part of the workflow.\"\n    },\n    {\n      \"id\": \"6749923b-1032-4adb-b805-eda6efd5ee1c\",\n      \"name\": \"Verify Approval Data\",\n      \"type\": \"n8n-nodes-base.code\",\n      \"position\": [\n        6340,\n        4060\n      ],\n      \"parameters\": {\n        \"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 };\"\n      },\n      \"typeVersion\": 2,\n      \"notes\": \"This code node performs automated tasks as part of the workflow.\"\n    },\n    {\n      \"id\": \"c5e34da4-81ec-47dc-aacf-4d6e0cf4256c\",\n      \"name\": \"Retrieve Issue Request Details\",\n      \"type\": \"n8n-nodes-base.googleSheets\",\n      \"position\": [\n        6560,\n        3840\n      ],\n      \"parameters\": {\n        \"options\": {},\n        \"filtersUI\": {\n          \"values\": [\n            {\n              \"lookupValue\": \"={{ $json[\\\"Submission ID\\\"] }}\",","sourceCodeStart":1685,"sourceCodeEnd":1721,"githubUrl":"https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Code/0926_Code_Webhook_Create_Webhook.json#L1685-L1721","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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).","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.","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.","If zero-quantity approvals are legitimate in your process, change the business rule instead of the data."],"exampleFix":"// before\nif (input[\"Action\"] === \"approve\" && input[\"Approved Quantity\"] <= 0) throw new Error(\"Approved quantity must be greater than 0\");\n\n// after\nif (input[\"Action\"] === \"approve\") {\n  const qty = Number(input[\"Approved Quantity\"]);\n  if (!Number.isFinite(qty) || qty <= 0) {\n    throw new Error(`Approved Quantity must be a number > 0, got: ${JSON.stringify(input[\"Approved Quantity\"])}`);\n  }\n}","handlingStrategy":"validation","validationCode":"// In the Code node, before the throw:\nconst qty = Number(input[\"Approved Quantity\"]);\nconst action = String(input[\"Action\"] || '').toLowerCase();\nconst isValid = action === 'reject' || (action === 'approve' && Number.isFinite(qty) && qty > 0);\n// route invalid payloads to an error/notification branch instead of throwing","typeGuard":"function isValidApproval(p) {\n  return Boolean(p && p[\"Submission ID\"] &&\n    [\"approve\", \"reject\"].includes(p[\"Action\"]) &&\n    (p[\"Action\"] !== \"approve\" || (Number.isFinite(Number(p[\"Approved Quantity\"])) && Number(p[\"Approved Quantity\"]) > 0)));\n}","tryCatchPattern":"try {\n  if (!isValidApproval(input)) return [{ json: { invalidPayload: input } }]; // to error branch\n  return { json: input };\n} catch (e) {\n  throw new Error(`Approval validation failed: ${e.message}`);\n}","preventionTips":["Make quantity a required numeric field in the source form/Sheet.","Coerce with Number() and use Number.isFinite before comparisons — never compare raw form strings with <= 0.","Log the full payload on validation failure so field-name drift is obvious.","Return invalid submissions to a review branch rather than halting the workflow."],"tags":["n8n","validation","code-node","approval-workflow","data-quality"],"backgroundTag":null,"analyzedSha":"94007c1445d9258a7da116646b79473e7c7c3282","analyzedAt":"2026-08-15T04:10:37.591Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}