Calendar Events not posting to the appropriate calendar

297 views
Skip to first unread message

Samuel Butterfield

unread,
Nov 3, 2023, 1:15:55 PM11/3/23
to Google Apps Script Community
Hi,

I have a script that creates calendar events from a Google Sheet, it super basic and creates the events as desired. However, I cannot get the events to post to anything other than my default calendar. I want them to post to a shared calendar and despite using the calendar ID in the script it will not work and continues to post to my default calendar.

I have tried multiple different calendar IDs and none are working. In the example below I replaced the actual calendar ID with a placeholder.

Here is the portion of the code that creates the calendar event. Hopefully someone has some suggestions or could point out something I am missing.

Thanks!

// Create a new calendar event.
var cal = CalendarApp.getCalendarById("Calendar ID");
var event = CalendarApp.createEvent(eventTitle, new Date(theStart), new Date(theEnd));


// Add the event description.
event.setDescription(eventDescription);


// Add the event location
event.setLocation(eventlocation);


// Write the calendar ID to a cell in S of the current row.
    sheet.getRange(i, 17).setValue(event.getId());

Andrew Roberts

unread,
Nov 4, 2023, 6:21:44 AM11/4/23
to google-apps-sc...@googlegroups.com
"Calendar Id" needs to be a constant, like CALENDAR_ID, assigned to the ID of the calendar you are trying to access.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/1221439f-74bc-4cbb-b391-f25f182d5aa7n%40googlegroups.com.

Laurie Nason

unread,
Nov 5, 2023, 12:41:49 AM11/5/23
to google-apps-sc...@googlegroups.com
I think as well as Andrew's response - you probably need to use the cal object you create at the beginning - rather than using the default CalendarApp to create the event - my suspicion (not tested) is that this will default to the default calendar as you have noticed rather than using the one specified by the calendar ID in the first line. 
Laurie



--

Laurie


Reply all
Reply to author
Forward
0 new messages