What this error means:
The error "TypeError: Cannot read property 'length' of undefined" indicates that the code is trying to access the length
property of a variable that is currently undefined
. In this case, it seems that the variable inputdata.codbar
is not being passed correctly from the previous step, leading to the error when the code attempts to use it.
Hi
You are exactly correct. But we need to see a screenshot of the input data to know why this is happening. Are you mapping the data correctly?
Hi
For us to have more info about the error, post screenshots showing how your Zap Code step is configured along with including the Code.
TIP: Try asking ChatGPT for help with your code.
3131415;25442011;25442640;6019602-2;V3.4.36;630
THAT IS THE QR DATA OF THE QR

Can you provide the full JavaScript code?
// this is wrapped in an `async` function
// you can use await throughout the function
// reemplaza con la variable que Zapier te pase
let stringzap = inputData.codbar;
let largo = stringzap.length;
// rest of your code
let posicion = stringzap.indexOf(';');
const clave_prodzap = stringzap.substring(0,posicion);
let posicion2 = stringzap.indexOf(';',posicion+1)
let inicialzap = stringzap.substring(posicion+1,posicion2);
let posicion3 = stringzap.indexof(';',posicion2+1);
let finalzap = stringzap.substring(posicion2+1,posicion3);
let posicion4 = stringzap.indexof(';',posicion3+1);
let posicion5 = stringzap.indexof(';',posicion4+1);
let posicion6 = stringzap.indexof(';',posicion5+1);
let posicion7 = stringzap.indexof(';',posicion6+1);
let cantzap = stringzap.substring(posicion6+1,posicion7);
let posicion8 = inicialzap.indexOf('H');
if (posicion8 = 0) {
´let numero = inicialzap.substring(5,6);
let prefijozap=inicialzap.substring(0,5);
numero = inicialzap;
}
else
{
let numero = inicialzap;
prefijozap='';
}
let numeroEntero = parseInt(numero, 10);
for (i = 0; i <= cantzap; i++) {
numeroentero = inicialzap + i;
serialarray = serialarray + prefijozap + numeroentero.tostring.padStart(6, '0') + ';';
}
output {serialarray};
What happened to the screenshot of the Code step and input value?
Try this Code from ChatGPT:
let stringzap = inputData.codbar;
// Step 1: Parse QR code segments
let parts = stringzap.split(';');
let inicialzap = partsr1];
let cantzap = parseInt(partsr5], 10); // sixth item is the count
// Step 2: Get prefix/starting number
let prefijozap = '';
let numero = '';
if (inicialzap.startsWith('H')) {
numero = inicialzap.substring(5, 6);
prefijozap = inicialzap.substring(0, 5);
} else {
numero = inicialzap;
}
let numeroEntero = parseInt(numero, 10);
// Step 3: Generate serials efficiently using an array
let serialArray = ];
for (let i = 0; i <= cantzap; i++) {
let numeroActual = numeroEntero + i;
let serial = prefijozap + numeroActual.toString().padStart(6, '0');
serialArray.push(serial);
}
// Step 4: Return as semicolon-separated string OR array
return {
serialarray: serialArray.join(';'), // or just return serialArray
count: serialArray.length
};
all these with the code you sendme
Failed to run your code
Your code had an error. See details below: Error: Sandbox.Timedout: RequestId: df63fbed-7322-4956-a414-9d84f5d051a1 Error: Task timed out after 10.00 seconds
What this error means:
The error "TypeError: Cannot read property 'length' of undefined" indicates that the JavaScript code is attempting to access the length
property of a variable that is currently undefined
. In this case, it likely means that the input data codbar
is not being passed correctly from the previous step, resulting in the variable stringzap
being undefined.
How to fix it:
- Check Previous Step Output: Ensure that the previous step (BranchingAPI) is correctly outputting the expected value for
Codigo_Barras
. Verify that the output contains the expected data format. - Test Input Data: In the Code by Zapier step, test the input data to confirm that
{{308132689__data__value__Codigo_Barras}}
is returning a valid string. If it’s empty or undefined, the code will fail. - Add Error Handling: Modify the JavaScript code to include error handling that checks if
inputData.codbar
is defined before proceeding with the parsing logic. This can prevent the code from failing if the input is not as expected. - Review Zap Configuration: Ensure that the Zap is configured correctly and that all necessary fields are filled out in the previous steps to pass the required data to this step.
Did you try working with ChatGPT to fix your code?
Share screenshots of your config/errors and share you code so the AI has context.
If you need to hire help, there is a directory of Certified Zapier Experts: https://zapier.com/experts
YES I FIX MY CODE THANKS
HAVE ANOTHER ERROR
BUT ALL AROUND THE SAME FACTOR
Best to continue to work with ChatGPT to get your code corrected.
Try the revised code above.
new code is this
// Get the QR code data string from inputData let stringzap = inputData.codbar; // Example: "3131415;25442011;25442640;6019602-2;V3.4.36;630" // Parse the first value: product key (before the first semicolon) let posicion = stringzap.indexOf(';'); let clave_prodzap = stringzap.substring(0, posicion); // Parse the second value: "inicialzap" (after first semicolon) let posicion2 = stringzap.indexOf(';', posicion + 1); let inicialzap = stringzap.substring(posicion + 1, posicion2); // Parse the third value: "finalzap" (after second semicolon) let posicion3 = stringzap.indexOf(';', posicion2 + 1); let finalzap = stringzap.substring(posicion2 + 1, posicion3); // Skip parsing 4th and 5th segments — they are not used here let posicion4 = stringzap.indexOf(';', posicion3 + 1); let posicion5 = stringzap.indexOf(';', posicion4 + 1); let posicion6 = stringzap.indexOf(';', posicion5 + 1); // Parse the 6th value: quantity of serials to generate let posicion7 = stringzap.length; let cantzap = stringzap.substring(posicion6 + 1, posicion7); // Initialize prefix and serial number variables let prefijozap = ''; let numero = ''; // Check if "inicialzap" starts with an "H" (special case) let posicion8 = inicialzap.indexOf('H'); if (posicion8 === 0) { // If it starts with H, treat the first 5 chars as a prefix and 6th char as the number numero = inicialzap.substring(5, 6); prefijozap = inicialzap.substring(0, 5); } else { // Otherwise, treat the full string as the number numero = inicialzap; prefijozap = ''; } // Convert extracted strings to integers for arithmetic let numeroEntero = parseInt(numero, 10); let cantidad = parseInt(cantzap, 10); // Initialize output string let serialarray = '';
Did you try this revised code?
Try this Code from ChatGPT:
let stringzap = inputData.codbar;
// Step 1: Parse QR code segments
let parts = stringzap.split(';');
let inicialzap = partsr1];
let cantzap = parseInt(partsr5], 10); // sixth item is the count
// Step 2: Get prefix/starting number
let prefijozap = '';
let numero = '';
if (inicialzap.startsWith('H')) {
numero = inicialzap.substring(5, 6);
prefijozap = inicialzap.substring(0, 5);
} else {
numero = inicialzap;
}
let numeroEntero = parseInt(numero, 10);
// Step 3: Generate serials efficiently using an array
let serialArray = ];
for (let i = 0; i <= cantzap; i++) {
let numeroActual = numeroEntero + i;
let serial = prefijozap + numeroActual.toString().padStart(6, '0');
serialArray.push(serial);
}
// Step 4: Return as semicolon-separated string OR array
return {
serialarray: serialArray.join(';'), // or just return serialArray
count: serialArray.length
};
yes
same error
hi thanks the code i working
the output information is send in a array of objects
the question how i can have access to this information from another function in zap
can you help me?
Help link for how to map variables between Zap steps: https://help.zapier.com/hc/en-us/articles/8496343026701-Send-data-between-steps-by-mapping-fields
Storage options:
- Zapier Table: https://zapier.com/apps/zapier-tables/integrations#triggers-and-actions
- Storage: https://zapier.com/apps/storage/integrations#triggers-and-actions
- Airtable: https://zapier.com/apps/airtable/integrations#triggers-and-actions
The error means inputdata.codbar
is undefined, so the code can't read its .length
. Ensure codbar
is correctly passed before accessing it.
Before accessing .length
, check if inputdata.codbar
is defined:
if (inputdata && inputdata.codbar) { const length = inputdata.codbar.length; // Proceed with logic } else { console.error("codbar is undefined or missing"); }
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.