Can anyone help me clean this up so it will work? I don't know Javascript and I just need to know enough to make this particular automated task work.
I'm trying to create a zap in Zapier to parse an email into usable bits to pass on to Google Sheets and Salesforce. First, I pass the email through the formatter to replace all of the carriage retus with ::::: as a delimiter.
The emails are labeled using a Gmail filter and are always have 2 or more of the following fields, but often times not all of them:
Full Name Organization Email
Phone Number How did you hear about _____ _____ty? What else?
I tried created a script using this video: https://www.youtube.com/watch?v=pTqhr6uZ2AE
I came up with this:
/*
EXAMPLE:
input.messy_data_from_previous_trigger_or_action = 'This is a single string of text that contains lots of different data. {"name": "John"} Sometimes when you are building a Zap, you will need to pull out one piece of data from a long, messy string of text. {"email": "johnsmith@gmail.com"} Thankfully, you can use the "Formatter by Zapier" app or the "Code by Zapier" app to extract the information you need.'
*/
function extract_piece_of_data(entire_string_of_text, characters_before_desired_data, characters_after_desired_data) {
var desired_data_with_stuff_after_it = entire_string_of_text.substr(entire_string_of_text.indexOf(characters_before_desired_data) + characters_before_desired_data.length);
var desired_data = desired_data_with_stuff_after_it.substr(0, desired_data_with_stuff_after_it.indexOf(characters_after_desired_data));
retu desired_data;
}
// Get the messy data string from Zapier's built-in "input" variable.
var messy_data = input.messy_data_from_previous_trigger_or_action;
// Remember to escape any double quotes in your function arguments with the backslash () character
var name = extract_piece_of_data(messy_data, “Name:::::”, “:::::”);
var organization = extract_piece_of_data(messy_data, “Organization:::::”, “:::::”);
var email = extract_piece_of_data(messy_data, “Email::::”, “<contact“);
var how = extract_piece_of_data(messy_data, “ty?:::::”, “:::::”);
var whatelse = extract_piece_of_data(messy_data, “se?:::::”, “:::::”);
// Output the data as an object called "output". The object's keys can be whatever you want. In this example, I chose to use the keys first_name and email_address.
output = {first_name: name, organization: organization, email_address: email, how: how, what_else: whatelse};
But, I keep getting an error message in Zapier.
Bargle. We hit an error creating a run javascript. :-( Error:
ReferenceError: sample is not defined theFunction (eval at <anonymous> (/var/task/index.js:47:23), <anonymous>:15:8) eval (eval at <anonymous> (/var/task/index.js:47:23), <anonymous>:31:20) /var/task/index.js:48:5 b (domain.js:183:18) Domain.run (domain.js:123:23) module.exports.handler (/var/task/index.js:46:5)
