Question

Reporting from Google Calendar into Google sheets with code step

  • 20 July 2021
  • 2 replies
  • 172 views

Hello,

Together with some help of a developer, I was able to write some code that would extract the required info from a Google Calendar appointment, into Google Sheets as a reporting. Finally it sends a feedback form to the participants who did not decline the event, through gmail. 

For testing I used the “find event in calendar” function, as this returns certain data and when you run a test, you can use this Mockup data, to test your code. This all worked perfectly. 

 

Now when I put the code live, it doesn’t run anymore. It gives me the feeling, like it cannot be processed in a dynamic way (As in pulling the data and processing it, when it doesn’t know yet before what the data is going to be). As reporting happens after an event, I start with the “event ends” trigger, and actually the “find event” trigger would be redundant. When I removed the “find event” it caused more issues, as apparently not all variables are available for some reasons. 

 

Step 1 - Event ended in google calendar (Works)

 

Step 2 - Find the event in google calendar (does exactly the same as step 1, but enables the variable “attendeesResponses”) (Works)

 

Step 3 - Sent run javascript to code (Works) - here the data in AND the data out is correct. See code below. 

 

Step 4 - sent 1 new spreadsheet row to google sheets (this runs, but empty). The variables that were used, were the ones that were the output of the javascript and some generic ones that were already available from step 1 (time of the event, etc.). These variables were recognized by zapier as variables that could be selected, but were not filled with content. All rows remained empty. When I test the zap step by step it pulls up results in step 1, 2 and 3 and then fills these results into a spreadsheet row in step 4. This doesn’t happen when I turn the zap on, and the rows remain empty.  

 

Step 5 - Send an Email in Gmail to the recipients: output “email_not_declined” variable. >> Gmail hit an error, so the run has been rescheduled in the future. In the output of step 3 I see the emailadresses that the email should be send to (which is good). But somehow step 5 cannot access this variable, to actually send the email to these recipients and therefore it pauses the zap.  

 

→ First question: can I somehow skip step 2, as it is double and increases room for error?

Second question: does anyone know, why step 4 doesn’t access the data when the zap runs in a real-life setting, but it does when I test it step by step? (and of course how to solve this?)

 

Thank you! 

 

Code

Input data:

trainerEmail » (organizer Email in Google calendar)

attendeesEmails » (Attendee Emails in Google calendar)

attendeesResponses » (Attendees Response Status in Google calendar)

 

// 1.1 Create arrays from stringified input data 


var attendeesEmailArray = inputData.attendeesEmails.split(',');
var attendeesResponsesArray = inputData.attendeesResponses.split(',');


// 1.2 Create an array that contains objects with two fields: email and response.

var attendees = attendeesEmailArray.map((email, index) => ({
  email,
  response: attendeesResponsesArray[index]
}));

 

// 1.3 Remove unwanted attendees (Trainer and the meeting room)
attendees = attendees.filter(attendee => {
  var email = attendee.email
  return (
    !email.includes('@resource.calendar.google.com') &&   
    email !== inputData.trainerEmail
  )
});

 

// 1.4 Count the sum of registrations and separate them based on their status
var countRegistered = attendees.length;


var countAccepted = attendees.filter(attendee => attendee.response === 'accepted').length;
var countDeclined = attendees.filter(attendee => attendee.response === 'declined').length;
var countTentative = attendees.filter(attendee => attendee.response === 'tentative').length;
var countNeedsAction = attendees.filter(attendee => attendee.response === 'needsAction').length;

 

// 1.5 an overview for quality check purposes and potential future use in Zapier
let emailRegistered = attendees.map(attendee => attendee.email).toString();
let overviewResponses = attendees.map(attendee => attendee.response).toString();

 

// 1.6 create a string with all the email addresses that have the status "accepted","tentative" or "needsAction"
var notDeclinedEmails = attendees.filter(attendee => attendee.response !== 'declined').map(attendee => attendee.email).toString();

 

// 1.7 create a string with all the email addresses that have the status  "declined"
var declinedEmails = attendees.filter(attendee => attendee.response === 'declined').map(attendee => attendee.email).toString();

 

// 1.8 define the output 
output = [{
  count_registered: countRegistered,
  count_accepted: countAccepted,
  count_declined: countDeclined,
  count_tentative: countTentative,
  count_needs_action: countNeedsAction,
  email_Registered: emailRegistered,
  email_not_declined: notDeclinedEmails,
  email_declined: declinedEmails,
  overview_responses: overviewResponses
}];

 

 

 

 


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

2 replies

Userlevel 7
Badge +12

Hi @Roel vd Berg 

 

If you are interested in hiring out to fix the issue, we would be happy to get the zap working correctly for you. 

If not, it would be helpful if you could share detailed screenshots of your zap and the configuration of each step. It is hard to troubleshoot with the information provided as there are potentially many things that could be wrong.


Lastly, if step 2 is what pulls in the attendee information and it is not available from your trigger step you cannot remove that step. 

Thank you for your reply. At this time I am not interested in the service - I was hoping that there were some people who would know the answer and are keen on sharing it! 

 

Based on what happens, I assume the issue lies between the data in and data out in the spreadsheet (see pictures 3, 4 and 5). Most important here is picture 5. The variables are there but these are empty. 

This is the case, because there might be an event in the future, that didn’t take place yet. I can search for the event and the variables are there, but the values aren’t there until it took place. I feel, as if Zapier is not able to work with variables that are empty now, but will be filled when it runs.  

 

When I take an event from the past and I do the tests, all steps work. 

 

Anyone has some thoughts on this? 

 

Picture 1 - the structure 

 

Picture 2 - data out from the javascript 

 

Picture 3 - data in Spreadsheet

 

Picture 4 - data out spreadsheet 


Picture 5 - Action in spreadsheet (top-part)