{"record":{"id":"014c8e233e3f49c4","repo":"Zie619/n8n-workflows","slug":"invalid-quantity-requested-quantityrequested","errorCode":null,"errorMessage":"Invalid quantity Requested: ${quantityRequested}. Must be greater than 0","messagePattern":"Invalid quantity Requested: (.+?)\\. Must be greater than 0","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"workflows/Code/0926_Code_Webhook_Create_Webhook.json","lineNumber":1591,"sourceCode":"      \"parameters\": {\n        \"sendTo\": \"example@gmail.com\",\n        \"message\": \"=<!DOCTYPE html>\\n<html lang=\\\"en\\\">\\n<head>\\n  <meta charset=\\\"UTF-8\\\">\\n  <meta name=\\\"viewport\\\" content=\\\"width=device-width, initial-scale=1.0\\\">\\n  <title>Low Stock Alert</title>\\n  <style>\\n    body {\\n      font-family: Arial, sans-serif;\\n      line-height: 1.6;\\n      color: #333;\\n      background-color: #f4f4f4;\\n      margin: 0;\\n      padding: 0;\\n    }\\n    .container {\\n      width: 80%;\\n      max-width: 600px;\\n      margin: 20px auto;\\n      background-color: #fff;\\n      padding: 20px;\\n      border-radius: 8px;\\n      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\\n    }\\n    h2 {\\n      color: #e74c3c;\\n      text-align: center;\\n    }\\n    p {\\n      margin: 10px 0;\\n    }\\n    .alert-message {\\n      background-color: #ffe6e6;\\n      padding: 15px;\\n      border-left: 4px solid #e74c3c;\\n      margin: 20px 0;\\n      font-weight: bold;\\n    }\\n    ul {\\n      list-style-type: none;\\n      padding: 0;\\n      margin: 20px 0;\\n      background-color: #f9f9f9;\\n      padding: 15px;\\n      border-left: 4px solid #3498db;\\n    }\\n    ul li {\\n      margin: 8px 0;\\n    }\\n    ul li strong {\\n      display: inline-block;\\n      width: 150px;\\n    }\\n    .action {\\n      text-align: center;\\n      margin: 20px 0;\\n    }\\n    .btn {\\n      display: inline-block;\\n      padding: 10px 20px;\\n      text-decoration: none;\\n      color: #fff;\\n      background-color: #3498db;\\n      border-radius: 5px;\\n      font-weight: bold;\\n    }\\n    .footer {\\n      text-align: center;\\n      margin-top: 20px;\\n      font-size: 0.9em;\\n      color: #777;\\n    }\\n  </style>\\n</head>\\n<body>\\n  <div class=\\\"container\\\">\\n    <h2>Low Stock Alert</h2>\\n    <p>Dear Stock Manager,</p>\\n\\n    <p>We have detected a low stock level for the following material:</p>\\n\\n    <div class=\\\"alert-message\\\">\\n      {{ $json[\\\"Alert Message\\\"] }}\\n    </div>\\n\\n    <ul>\\n      <li><strong>Product ID:</strong> {{ $json[\\\"Product ID\\\"] }}</li>\\n      <li><strong>Material:</strong> {{ $json[\\\"Material Name\\\"] }}</li>\\n      <li><strong>Current Stock:</strong> {{ $json[\\\"Current Stock\\\"] }} {{ $json[\\\"Measurement Unit\\\"] }}</li>\\n      <li><strong>Minimum Stock:</strong> {{ $json[\\\"Minimum Stock Level\\\"] }} {{ $json[\\\"Measurement Unit\\\"] }}</li>\\n    </ul>\\n\\n    <div class=\\\"action\\\">\\n      <p>Please take action to reorder this material.</p>\\n      <a href=\\\"{{ $env.WEBHOOK_URL }}\\\" class=\\\"btn\\\">Reorder Now</a>\\n    </div>\\n\\n    <div class=\\\"footer\\\">\\n      <p>Regards,<br>Your Company</p>\\n    </div>\\n  </div>\\n</body>\\n</html>\",\n        \"options\": {},\n        \"subject\": \"Low Stock Alert: Immediate Action Required\"\n      },\n      \"typeVersion\": 2.1,\n      \"notes\": \"This gmail node performs automated tasks as part of the workflow.\"\n    },\n    {\n      \"id\": \"ac8781e9-f694-467d-b40b-95bdbab98880\",\n      \"name\": \"Validate Issue Request Data\",\n      \"type\": \"n8n-nodes-base.code\",\n      \"position\": [\n        6340,\n        3400\n      ],\n      \"parameters\": {\n        \"jsCode\": \"const input = $input.all()[0].json;\\nconst quantityRequested= input[\\\"Quantity Requested\\\"];\\n\\nif (quantityRequested <= 0) throw new Error(`Invalid quantity Requested: ${quantityRequested}. Must be greater than 0`);\\n\\nreturn { json: input };\"\n      },\n      \"typeVersion\": 2,\n      \"notes\": \"This code node performs automated tasks as part of the workflow.\"\n    },\n    {\n      \"id\": \"6d88db70-6b4f-47c5-8093-ab339762edbe\",\n      \"name\": \"Verify Requested Quantity\",\n      \"type\": \"n8n-nodes-base.code\",\n      \"position\": [\n        6560,\n        3400\n      ],\n      \"parameters\": {\n        \"jsCode\": \"const input = $input.all()[0].json;\\nconst quantityRequested = input[\\\"Quantity Requested\\\"];\\nif (!input[\\\"Product ID\\\"]) throw new Error(\\\"Product ID is missing\\\");\\nif (quantityRequested <= 0) throw new Error(`Invalid quantity requested: ${quantityRequested}`);\\nif (!input[\\\"Submission ID\\\"]) throw new Error(\\\"Submission ID is missing\\\");\\nreturn { json: input };\"\n      },\n      \"typeVersion\": 2,\n      \"notes\": \"This code node performs automated tasks as part of the workflow.\"\n    },","sourceCodeStart":1573,"sourceCodeEnd":1609,"githubUrl":"https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Code/0926_Code_Webhook_Create_Webhook.json#L1573-L1609","documentation":"Thrown by 'Validate Issue Request Data' when `Quantity Requested` from the issue-request webhook is <= 0. The check runs on the raw input (no parsing), so undefined also compares <= 0 in JS (undefined <= 0 is false - actually undefined converts to NaN, so NaN <= 0 is false; but '0', empty string '', and 0 all pass the throw). Empty string '' <= 0 is true, so blank submissions throw here.","triggerScenarios":"Submission with Quantity Requested = 0, '0', or '' (empty string); a -1 test value; input.readOnly draft submissions; type coercion surprises: '5abc' is NaN so it does NOT throw here and fails later.","commonSituations":"Request form allows 0 or blank quantity; form validation missing client-side; numeric field submitted as text with empty value.","solutions":["Parse first, then validate: use Number.isFinite and > 0 so both garbage and non-positive values are caught.","Enforce min=1 and required on the quantity field in the request form.","Include the raw value and its type in the error for diagnosis.","Route failures to an error-response branch that tells the requester instead of failing silently."],"exampleFix":"// before\nconst quantityRequested = input[\"Quantity Requested\"];\nif (quantityRequested <= 0) throw new Error(`Invalid quantity Requested: ${quantityRequested}. Must be greater than 0`);\n\n// after\nconst quantityRequested = Number(input[\"Quantity Requested\"]);\nif (!Number.isFinite(quantityRequested) || quantityRequested <= 0) {\n  throw new Error(`Invalid quantity Requested: ${JSON.stringify(input[\"Quantity Requested\"])}. Must be a number greater than 0`);\n}","handlingStrategy":"validation","validationCode":"const quantityRequested = Number(input['Quantity Requested']);\nif (!Number.isFinite(quantityRequested) || quantityRequested <= 0) {\n  throw new Error(`Invalid quantity Requested: ${JSON.stringify(input['Quantity Requested'])}. Must be greater than 0`);\n}","typeGuard":"const isValidRequestedQty = (v) => {\n  const n = Number(v);\n  return Number.isFinite(n) && n > 0;\n};","tryCatchPattern":null,"preventionTips":["Convert to Number before comparing - raw '<= 0' lets NaN slip through","Set min=1 and required on the request form","Echo the raw value (JSON.stringify) in the error","Route invalid submissions to a user-facing error response branch"],"tags":["n8n","webhook","validation","type-coercion","inventory"],"backgroundTag":null,"analyzedSha":"94007c1445d9258a7da116646b79473e7c7c3282","analyzedAt":"2026-08-15T04:10:37.591Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}