{"record":{"id":"e3a03c59041f43d0","repo":"Zie619/n8n-workflows","slug":"invalid-quantity-input-quantity-received","errorCode":null,"errorMessage":"Invalid quantity: ${input[\"Quantity Received\"]}","messagePattern":"Invalid quantity: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"workflows/Code/0926_Code_Webhook_Create_Webhook.json","lineNumber":800,"sourceCode":"          \"mode\": \"list\",\n          \"value\": \"1q0S6AVK7uxZG8sUQkpcZr01KToHPjOZ0gG3zKHLR6lw\",\n          \"cachedResultUrl\": \"{{ $env.WEBHOOK_URL }}\",\n          \"cachedResultName\": \"Plumbee Raw Material Delivery  (Responses)\"\n        }\n      },\n      \"typeVersion\": 4.5,\n      \"notes\": \"This googleSheets node performs automated tasks as part of the workflow.\"\n    },\n    {\n      \"id\": \"21c17077-9f9a-489a-b6a5-ea7a70a85cee\",\n      \"name\": \"Calculate Total Price\",\n      \"type\": \"n8n-nodes-base.code\",\n      \"position\": [\n        6340,\n        2040\n      ],\n      \"parameters\": {\n        \"jsCode\": \"// Get the input data\\nconst input = $input.all()[0].json;\\n\\n// Debug: Log the entire input to see all available fields\\nconsole.log(\\\"Complete Input Data:\\\", JSON.stringify(input, null, 2));\\n\\n// Improved number parser that handles different formats\\nconst getNumber = (value) => {\\n  if (value === undefined || value === null || value === \\\"\\\") return null;\\n  \\n  // Remove any currency symbols, commas, or extra spaces\\n  const cleaned = String(value)\\n    .replace(/[^\\\\d.-]/g, '')\\n    .trim();\\n    \\n  const num = parseFloat(cleaned);\\n  return isNaN(num) ? null : num;\\n};\\n\\n// Use EXACT field names from your webhook payload\\nconst quantity = getNumber(input[\\\"Quantity Received\\\"]);  // Not \\\"Quantity Received\\\"\\nconst unitPrice = getNumber(input[\\\"Unit Price\\\"]);    // Not \\\"Unit Price\\\"\\n\\n// Validate\\nif (quantity === null) throw new Error(`Invalid quantity: ${input[\\\"Quantity Received\\\"]}`);\\nif (unitPrice === null) throw new Error(`Invalid price: ${input[\\\"Unit Price\\\"]}`);\\n\\n// Calculate total\\nconst totalPrice = quantity * unitPrice;\\n\\n// Return results\\n// Return clean output without debug info\\nreturn {\\n  json: {\\n    \\\"Timestamp\\\": new Date().toISOString(),\\n    \\\"Product ID\\\": input[\\\"Product ID\\\"],\\n    \\\"Supplier Name\\\": input[\\\"Supplier Name\\\"],\\n    \\\"Material Name\\\": input[\\\"Material Name\\\"],\\n    \\\"Quantity Received\\\": quantity,\\n    \\\"Description\\\": input[\\\"Description\\\"] || \\\"\\\",\\n    \\\"Measurement Unit\\\": input[\\\"Measurement Unit\\\"],\\n    \\\"Unit Price\\\": unitPrice,\\n    \\\"Total Price\\\": totalPrice.toFixed(2),\\n    \\\"Date of Delivery\\\": input[\\\"Date of Delivery\\\"],\\n    \\\"Received By\\\": input[\\\"Received By\\\"],\\n    \\\"Submission ID\\\": input[\\\"Submission ID\\\"]\\n  }\\n};\"\n      },\n      \"typeVersion\": 2,\n      \"notes\": \"This code node performs automated tasks as part of the workflow.\"\n    },\n    {\n      \"id\": \"4ce817b0-2283-438f-82c7-6f4901fffdd3\",\n      \"name\": \"Calculate Updated Current Stock\",\n      \"type\": \"n8n-nodes-base.code\",\n      \"position\": [\n        7640,\n        1840\n      ],\n      \"parameters\": {\n        \"mode\": \"runOnceForEachItem\",\n        \"jsCode\": \"const existingStock = parseFloat(\\n$('Lookup Existing Stock').first().json['Current Stock']\\n|| 0);\\nconst newQuantity = parseFloat(\\n  $('Validate Quantity Received').first().json['Quantity Received']);\\nconst updatedStock = existingStock + newQuantity;\\n\\n\\n  \\nreturn {\\n  json: {\\n    ...$json,\\n    \\\"Updated Current Stock\\\": updatedStock\\n  }\\n};\"\n      },\n      \"typeVersion\": 2,\n      \"notes\": \"This code node performs automated tasks as part of the workflow.\"","sourceCodeStart":782,"sourceCodeEnd":818,"githubUrl":"https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Code/0926_Code_Webhook_Create_Webhook.json#L782-L818","documentation":"Thrown by 'Calculate Total Price' when the webhook field `Quantity Received` cannot be parsed to a number. The getNumber helper strips non-numeric characters, runs parseFloat, and returns null for undefined/null/empty/NaN - the throw then reports the raw value.","triggerScenarios":"Webhook form submitted with Quantity Received missing, empty string, or a value like 'abc' or ' pieces' that strips to nothing; field name mismatch (form sends 'quantity_received' or 'Qty Received'); value 0 is NOT rejected (parseFloat('0')=0 passes), so this specifically means unparseable input.","commonSituations":"Google Form / front-end form field renamed or made optional; respondents typing free text into a numeric field; leading/trailing currency or unit words in the value; webhook payload schema drift.","solutions":["Make Quantity Received required and numeric at the form layer (input type=number, min>0).","Check the exact field name in the arriving payload via the console.log of complete input data already present in the node.","Trim units: extend the cleaner to also strip letters, or send machine-formatted values from the form.","If zero-quantity submissions are invalid too, change the check to quantity === null || quantity <= 0."],"exampleFix":"// before\nconst quantity = getNumber(input[\"Quantity Received\"]);\nif (quantity === null) throw new Error(`Invalid quantity: ${input[\"Quantity Received\"]}`);\n\n// after\nconst quantity = getNumber(input[\"Quantity Received\"]);\nif (quantity === null || quantity <= 0) {\n  throw new Error(`Invalid quantity: ${JSON.stringify(input[\"Quantity Received\"])} (field names present: ${Object.keys(input).join(', ')})`);\n}","handlingStrategy":"validation","validationCode":"const qtyRaw = input['Quantity Received'];\nconst qtyNum = Number(String(qtyRaw ?? '').replace(/[^\\d.-]/g, ''));\nif (!Number.isFinite(qtyNum) || qtyNum <= 0) {\n  throw new Error(`Invalid quantity: ${JSON.stringify(qtyRaw)} (keys: ${Object.keys(input).join(', ')})`);\n}","typeGuard":"const isValidQuantity = (v) => {\n  if (v === undefined || v === null || v === '') return false;\n  const n = parseFloat(String(v).replace(/[^\\d.-]/g, ''));\n  return Number.isFinite(n) && n > 0;\n};","tryCatchPattern":null,"preventionTips":["Make quantity required and numeric (min>0) in the submitting form","Match field names exactly between the form payload and the Code node","Echo available keys in validation errors","Validate at the webhook entry so bad data never reaches calculation nodes"],"tags":["n8n","webhook","form-validation","number-parsing","inventory"],"backgroundTag":null,"analyzedSha":"94007c1445d9258a7da116646b79473e7c7c3282","analyzedAt":"2026-08-15T04:10:37.591Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}