Hoping someone with Javascript expertise can help me out. What I am trying to do is send the final output data into an Airtable field. I have done this in another Zap where the trigger is a webflow form and basically have tried to adjust the code to work with a webhook instead.
I have the following setup:
Trigger: Catch Hook
Action: Code by Zapier. In the input data I have the following;
Then I have the following code:
var hookBootcamps = inputData.bootcamp var hookPrenatal = inputData.prenatal var hookPostnatal = inputData.postnatal var hookMentalHealth = inputData.mentalHealth var hookLifestyle = inputData.lifestyle var hookBodyTransformation = inputData.bodyTransformation var hookBodybuilding = inputData.bodybuilding var hookStrengthConditioning = inputData.strengthConditioning var hookNutrition = inputData.nutrition
var bootcamp var prenatal var postnatal var mentalHealth var lifestyle var bodyTransformation var bodybuilding var strengthConditioning var nutrition
if (hookBootcamps == "true") { bootcamp = "Bootcamp" } else if (hookBootcamps == "false") { bootcamp = "" }
if (hookPrenatal == "true") { prenatal = "Prenatal" } else if (hookPrenatal == "false") { prenatal = "" }
if (hookPostnatal == "true") { postnatal = "Postnatal" } else if (hookPostnatal == "false") { postnatal = "" }
if (hookMentalHealth == "true") { mentalHealth = "Mental Health" } else if (hookMentalHealth == "false") { mentalHealth = "" }
if (hookLifestyle == "true") { lifestyle = "Lifestyle" } else if (hookLifestyle == "false") { lifestyle = "" }
if (hookBodyTransformation == "true") { bodyTransformation = "Body Transformation" } else if (hookBodyTransformation == "false") { bodyTransformation = "" }
if (hookBodybuilding == "true") { bodybuilding = "Bodybuilding" } else if (hookBodybuilding == "false") { bodybuilding = "" }
Thanks very much, I was able to rectify a lot of the errors with the tool.
Only one error at the end is:
Line
Col
Errors
75
1
‘output’ is not defined
var hookBootcamps = 'inputData.bootcamp'; var hookPrenatal = 'inputData.prenatal'; var hookPostnatal = 'inputData.postnatal'; var hookMentalHealth = 'inputData.mentalHealth'; var hookLifestyle = 'inputData.lifestyle'; var hookBodyTransformation = 'inputData.bodyTransformation'; var hookBodybuilding = 'inputData.bodybuilding'; var hookStrengthConditioning = 'inputData.strengthConditioning'; var hookNutrition = 'inputData.nutrition';
var bootcamp; var prenatal; var postnatal; var mentalHealth; var lifestyle; var bodyTransformation; var bodybuilding; var strengthConditioning; var nutrition;
if (hookBootcamps == "true") { bootcamp = "Bootcamp"; } else if (hookBootcamps == "false") { bootcamp = ""; }
if (hookPrenatal == "true") { prenatal = "Prenatal"; } else if (hookPrenatal == "false") { prenatal = ""; }
if (hookPostnatal == "true") { postnatal = "Postnatal"; } else if (hookPostnatal == "false") { postnatal = ""; }
if (hookMentalHealth == "true") { mentalHealth = "Mental Health"; } else if (hookMentalHealth == "false") { mentalHealth = ""; }
if (hookLifestyle == "true") { lifestyle = "Lifestyle"; } else if (hookLifestyle == "false") { lifestyle = ""; }
if (hookBodyTransformation == "true") { bodyTransformation = "Body Transformation"; } else if (hookBodyTransformation == "false") { bodyTransformation = ""; }
if (hookBodybuilding == "true") { bodybuilding = "Bodybuilding"; } else if (hookBodybuilding == "false") { bodybuilding = ""; }
Tried removing the single quotes as suggested but not working either.
Appreciate your help on this but I reckon I may need to hire someone to build for me as I really don’t know Javascript…
It is strange though the code is the same as another Zap I’m using but Webflow form is the trigger and it works perfectly so not sure where I’m going wrong with this. It’s obviously down to the difference in the input source being a webhook.
FYI here is the other Zap that works:
var webFlowBootcamps = inputData.bootcamp var webFlowPrenatal = inputData.prenatal var webFlowPostnatal = inputData.postnatal var webFlowMentalHealth = inputData.mentalHealth var webFlowLifestyle = inputData.lifestyle var webFlowBodyTransformation = inputData.bodyTransformation var webFlowBodybuilding = inputData.bodybuilding var webFlowStrengthConditioning = inputData.strengthConditioning var webFlowNutrition = inputData.nutrition
var bootcamp var prenatal var postnatal var mentalHealth var lifestyle var bodyTransformation var bodybuilding var strengthConditioning var nutrition
if (webFlowBootcamps == "true") { bootcamp = "Bootcamp" } else if (webFlowBootcamps == "false") { bootcamp = "" }
if (webFlowPrenatal == "true") { prenatal = "Prenatal" } else if (webFlowPrenatal == "false") { prenatal = "" }
if (webFlowPostnatal == "true") { postnatal = "Postnatal" } else if (webFlowPostnatal == "false") { postnatal = "" }
if (webFlowMentalHealth == "true") { mentalHealth = "Mental Health" } else if (webFlowMentalHealth == "false") { mentalHealth = "" }
if (webFlowLifestyle == "true") { lifestyle = "Lifestyle" } else if (webFlowLifestyle == "false") { lifestyle = "" }
if (webFlowBodyTransformation == "true") { bodyTransformation = "Body Transformation" } else if (webFlowBodyTransformation == "false") { bodyTransformation = "" }
if (webFlowBodybuilding == "true") { bodybuilding = "Bodybuilding" } else if (webFlowBodybuilding == "false") { bodybuilding = "" }
Try this cleaned up and simplified Javascript Code:
var webFlowBootcamps = inputData.bootcamp; var webFlowPrenatal = inputData.prenatal; var webFlowPostnatal = inputData.postnatal; var webFlowMentalHealth = inputData.mentalHealth; var webFlowLifestyle = inputData.lifestyle; var webFlowBodyTransformation = inputData.bodyTransformation; var webFlowBodybuilding = inputData.bodybuilding; var webFlowStrengthConditioning = inputData.strengthConditioning; var webFlowNutrition = inputData.nutrition;
var bootcamp = ""; var prenatal = ""; var postnatal = ""; var mentalHealth = ""; var lifestyle = ""; var bodyTransformation = ""; var bodybuilding = ""; var strengthConditioning = ""; var nutrition = "";
if (webFlowBootcamps == "true") { bootcamp = "Bootcamp"; }
if (webFlowPrenatal == "true") { prenatal = "Prenatal"; }
if (webFlowPostnatal == "true") { postnatal = "Postnatal"; }
if (webFlowMentalHealth == "true") { mentalHealth = "Mental Health"; }
if (webFlowLifestyle == "true") { lifestyle = "Lifestyle"; }
if (webFlowBodyTransformation == "true") { bodyTransformation = "Body Transformation"; }
if (webFlowBodybuilding == "true") { bodybuilding = "Bodybuilding"; }
Ok so that pulled in the names but not the values. See screenshot of test:
So tried adding the else if statement back in but that gave same result. Names but not values being pulled from the input.
@Kev Lawrence
Please post screenshots with how your Zap Code step is currently configured (inputs & code), thanks.
var webFlowBootcamps = inputData.bootcamp; var webFlowPrenatal = inputData.prenatal; var webFlowPostnatal = inputData.postnatal; var webFlowMentalHealth = inputData.mentalHealth; var webFlowLifestyle = inputData.lifestyle; var webFlowBodyTransformation = inputData.bodyTransformation; var webFlowBodybuilding = inputData.bodybuilding; var webFlowStrengthConditioning = inputData.strengthConditioning; var webFlowNutrition = inputData.nutrition;
var bootcamp = ""; var prenatal = ""; var postnatal = ""; var mentalHealth = ""; var lifestyle = ""; var bodyTransformation = ""; var bodybuilding = ""; var strengthConditioning = ""; var nutrition = "";
if (webFlowBootcamps == "true") { bootcamp = "Bootcamp"; }
if (webFlowPrenatal == "true") { prenatal = "Prenatal"; }
if (webFlowPostnatal == "true") { postnatal = "Postnatal"; }
if (webFlowMentalHealth == "true") { mentalHealth = "Mental Health"; }
if (webFlowLifestyle == "true") { lifestyle = "Lifestyle"; }
if (webFlowBodyTransformation == "true") { bodyTransformation = "Body Transformation"; }
if (webFlowBodybuilding == "true") { bodybuilding = "Bodybuilding"; }