Sometimes you want the result of a specific leadform answer to go into one specific field. Or multiple answers. This guide will show you how to do that.
The leadform answers are in a nested array in the array of the api-answer itself.
Which means you have to look into the array "Lead Form Answers", which itself then has to be parsed by finding the right answer-value while searching for the right question-value.
In this example, let's say we want to get all values of the question "Product" (so the multiple leadform answers given were "Cirrus Scarf" and "Cumulus Coat").
Now we add an action to our zap named "Code":
Let's run Javascript in it:
We tell it to have the input Data "text" and select the field "Lead Form Answers":
Now we tell the ai it should code for us:
Prompt: "search for all questions named 'Product' and put their answers in a comma-separated string"
Looks good:
Code:
const names = (inputData['questions[]name'] || '').split(',');
const answers = (inputData['questions[]answers'] || '').split(',');
// Initialize an array to hold the answers for questions named 'Product'
const productAnswers = [];
// Iterate through the names and collect answers for 'Product'
names.forEach((name, index) => {
if (name.trim() === 'Product') {
productAnswers.push(answers[index].trim());
}
});
// Join the collected answers into a comma-separated string
const answersString = productAnswers.join(',');
// Prepare the output object with the answers string
output = { answers: answersString };
Click on "Output Data" and "Run Code" to test it, if the result look good, press "Use Code":
Result of the final code configuration:
Now continue to test your step, the result of the test should be still right:
You can now map the output of the code module, in this example, a zapier table: