Derek Lee Derek Lee - 8 months ago 90
Javascript Question

getCreators() Type Error

I wrote the following function to try to get the user that created the gCal event.

To test this I created an event on calendar and tried to run the script. When the script executes it gets error: "TypeError: Cannot find function getCreators in object CalendarEvent. (line 68, file "Code")".

Any ideas why this is happening? I'm fairly certain getCreators() is a function in object CalendarEvent (Ref:

function getuser(instr) {
var today = new Date();
var scriptProperties=PropertiesService.getScriptProperties();
var instrcal= scriptProperties.getProperty(instr);
var event=CalendarApp.getCalendarById(instrcal).getEventsForDay(today);
if (event<1) {
var user= 'None'
else if (event>1) {
var user= 'Multiple Users'
else {
var user= event.getCreators()
return user


getEventsForDay returns an array of CalendarEvent objects, all events for that day, even if it is just one.
You'll need to go through the events to find the one you want and then call getCreators().

You can verify this by using

var event=CalendarApp.getCalendarById(instrcal).getEventsForDay(today)[0];

Here the call will work.