{"record":{"id":"526caaf6be8d3047","repo":"Zie619/n8n-workflows","slug":"invalid-price-input-unit-price","errorCode":null,"errorMessage":"Invalid price: ${input[\"Unit Price\"]}","messagePattern":"Invalid price: (.+?)","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 `Unit Price` cannot be parsed to a number by getNumber. Currency symbols, commas, and spaces are stripped before parseFloat, so this fires only when the remaining string is empty or non-numeric (NaN) or the field is absent.","triggerScenarios":"Unit Price missing from the webhook payload; value like 'per unit' or 'N/A'; field named differently in the form; value is an object/array because the form sent nested JSON.","commonSituations":"Price field optional in the form; free-text price inputs; currency strings that strip to nothing ('¥' alone); schema changes after form edits.","solutions":["Make Unit Price a required numeric field in the submitting form.","Verify the exact key via the node's existing console.log of full input.","Accept common formats explicitly: strip thousands separators correctly ('1,234.56' -> 1234.56) before parseFloat.","Guard downstream: skip the Google Sheets append and notify the submitter instead of failing the run."],"exampleFix":"// before\nconst unitPrice = getNumber(input[\"Unit Price\"]);\nif (unitPrice === null) throw new Error(`Invalid price: ${input[\"Unit Price\"]}`);\n\n// after\nconst parsePrice = (v) => {\n  if (typeof v !== 'string' && typeof v !== 'number') return null;\n  const cleaned = String(v).replace(/[,$\\s]/g, '');\n  const n = Number(cleaned);\n  return Number.isFinite(n) && n >= 0 ? n : null;\n};\nconst unitPrice = parsePrice(input[\"Unit Price\"]);\nif (unitPrice === null) throw new Error(`Invalid price: ${JSON.stringify(input[\"Unit Price\"])}`);","handlingStrategy":"validation","validationCode":"const priceRaw = input['Unit Price'];\nconst priceNum = Number(String(priceRaw ?? '').replace(/[,$\\s]/g, ''));\nif (!Number.isFinite(priceNum) || priceNum < 0) {\n  throw new Error(`Invalid price: ${JSON.stringify(priceRaw)}`);\n}","typeGuard":"const isValidPrice = (v) => {\n  if (typeof v !== 'string' && typeof v !== 'number') return false;\n  const n = Number(String(v).replace(/[,$\\s]/g, ''));\n  return Number.isFinite(n) && n >= 0;\n};","tryCatchPattern":null,"preventionTips":["Require numeric price input in the form; strip commas/currency in one shared parser","Confirm the exact field key via the node's full-input log","Reject or clean 'per unit'-style free text before submission","Guard the sheets append behind validation success"],"tags":["n8n","webhook","form-validation","price-parsing"],"backgroundTag":null,"analyzedSha":"94007c1445d9258a7da116646b79473e7c7c3282","analyzedAt":"2026-08-15T04:10:37.591Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}