Question

Online scheduling automation project - 'Code by Zapier' JavaScript "output" error

  • 8 May 2023
  • 0 replies
  • 41 views

Hi! 

I’m looking to automate an online scheduling service for my website. When the end user fills out the Google Form, I have the user select three date and time options. Then our team is to choose which would work best for us to then schedule this appointment based on that.

I’m having the automation work based on the ‘emoji reaction’ my team reacts (one two or three emoji), the Zapier code should choose option one, two, or three) and update the Google Calendar’s new detailed event accordingly.

 

Here’s what the Zapier flow currently looks like:

1. Google Form submission (trigger)

2. Send slack channel message with relevant Google Form details

3. Delay (only run Monday-Friday at 9 AM) 

4. Search for Slack message reaction of :one: emoji

5. Search for Slack message reaction of :two: emoji

6. Search for Slack message reaction of :three: emoji

7. Search for Slack message reaction of :x: emoji

8. Only continue if (:one: :two: or :three: are true)

9. Custom code (JavaScript)

10. Create detailed event in Google Calendar (based on which emoji reaction, set the date and time of that new event accordingly)

 

I’ve been trying to use ChatGPT and Bard AI to make this code for step 9 but it keeps getting errors. The main error I get is

Failed to run your JavaScript code
Error: You did not define `output`! Try `output = {id: 1, hello: "world"};`”

--------------------------------------------------------------------------

Here is the code that gives that error:

 

Zapier Input Data (variable name I give and the data it references. This is searching for the emoji reaction in the Slack channel for each submission):

:one: → Looks at Zap step 4. Zap Search Was Found Status: true/false

:two: → Looks at Zap step 5. Zap Search Was Found Status: true/false

:three: → Looks at Zap step 6. Zap Search Was Found Status: true/false

 

ChatGPT Code:

// Get the Zapier status of a step based on the name of the emoji.
function getZapierStatus(emojiName) {
// Get the value of the emoji reaction.
var reactionValue = getReactionValue(emojiName);

// Convert the reaction value to a boolean.
var reactionBoolean = (reactionValue === 'true');

// Return the boolean value as a string.
return reactionBoolean.toString();
}

// Update the Google Calendar based on the reaction.
function updateCalendar(reaction) {
// Get the previous Zapier statuses for steps :one: to :three:.
var statusOne = getZapierStatus(":one:");
var statusTwo = getZapierStatus(":two:");
var statusThree = getZapierStatus(":three:");

// Update the Google Calendar based on the status of the variables.
var output = "";
if (statusOne === "true") {
output = ":one:";
} else if (statusTwo === "true") {
output = ":two:";
} else if (statusThree === "true") {
output = ":three:";
} else {
output = "No emoji found";
}

// Update the Google Calendar with the reaction.
var calendar = getGoogleCalendar();
calendar.updateEvent(output);

// Return the output.
return output;
}

// Main function that runs when the Zap is triggered.
function run() {
// Get the reaction that triggered the Zap.
var reaction = getReaction();

// Check if the reaction is one of :one:, :two:, :three: or :x:.
var reactionName = reaction.get("emojiName");
if (reactionName === ":one:" || reactionName === ":two:" || reactionName === ":three:" || reactionName === ":x:") {
// Update the Google Calendar based on the reaction.
var output = updateCalendar(reaction);

// Send a confirmation message to the thread.
threadMessage("The event has been updated based on the " + reactionName + " reaction.");
} else {
// Send an error message to the thread.
threadMessage("Invalid emoji reaction.");
}
}

 


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.