Reputation: 61
Topline: I'm having a problem I don't understand; I can run this code if I do so manually in the script editor:
ScriptApp.newTrigger('functionname').forUserCalendar('usercalendar').onEventUpdated().create()
But, when I install the application from manifest and attempt to run the same code from the users perspective, I get an error "Exception: We're sorry, a server error occurred. Please wait a bit and try again. [line: 15, function: installTrigger, file: Code]"
Context: I'm working with a client to set up a conferencing extension for Google Calendar.
Part of that involves keeping their server roughly up to date with any calendar changes from the user - if I've got a conference meeting at 10am, but at the last minute I change it to 11am, the server needs to know!
The documentation actually has a section on this: https://developers.google.com/gsuite/add-ons/calendar/conferencing/sync-calendar-changes . The idea is the add-on installs a trigger that runs whenever an event gets updated. You need to do some filtering to make sure you're only sending relevant data, but that's the broad mechanism. I simply can't replicate the ability to create a calendar onEventUpdated trigger!
To demonstrate the issue, I've cut down the code to bare bones below. This code makes a sidebar available in google calendar with a button. When you click the button, it should install an onEventUpdated trigger on the calendar you've specified in the code.
Code.gs:
//Attempting to install an onEventUpdated - it appears I can't use 'forUserCalendar' when installing as a user, but can when I manually select 'installTrigger()' function in the code editor?
//Functionality/scopes based on those demonstrated here:
//https://developers.google.com/gsuite/add-ons/calendar/conferencing/sync-calendar-changes
//https://developers.google.com/gsuite/add-ons/calendar/conferencing/conferencing-sample?hl=fr#add-on-manifest
function onHomePageOpen(e) {
let newButton = CardService.newTextButton().setText('Try install sync').setOnClickAction(CardService.newAction().setFunctionName('installTrigger'))
let card = CardService.newCardBuilder()
.setHeader(CardService.newCardHeader()
.setTitle("<h1>Test install sync</h1>"))
.addSection(CardService.newCardSection().addWidget(newButton))
.build()
return card
}
function installTrigger(e) {
var triggerBuilder = ScriptApp.newTrigger('syncupdate');
var triggerBuilder2 = triggerBuilder.forUserCalendar('<<YOUR EMAIL IN HERE>>').onEventUpdated().create()
console.log('triggerBuilder2', triggerBuilder2)
}
function syncupdate() {
console.log('triggered on update of an event!');
}
manifest.json
{
"timeZone": "Pacific/Auckland",
"dependencies": {},
"oauthScopes": [
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/calendar.readonly",
"https://www.googleapis.com/auth/calendar.events",
"https://www.googleapis.com/auth/calendar.events.readonly",
"https://www.google.com/calendar/feeds",
"https://www.googleapis.com/auth/script.locale",
"https://www.googleapis.com/auth/calendar.addons.current.event.read",
"https://www.googleapis.com/auth/calendar.addons.execute",
"https://www.googleapis.com/auth/calendar.addons.current.event.write",
"https://www.googleapis.com/auth/script.scriptapp"
],
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"addOns": {
"common": {
"name": "Test Install Sync",
"logoUrl": "https://www.gstatic.com/companion/icon_assets/tasks2_2x.png",
"layoutProperties": {
"primaryColor": "#123763",
"secondaryColor": "#1a73e8"
},
"useLocaleFromApp": true
},
"calendar": {
"homepageTrigger": {
"runFunction": "onHomePageOpen"
},
"currentEventAccess": "READ_WRITE"
}
}
}
Upvotes: 3
Views: 369
Reputation: 15377
I've tested this out myself and it appears that no matter if the Calendar ID provided is a hard-coded string "[email protected]"
, retrieved from Session.getActiveUser().getEmail()
or using the keyword "primary"
, this error persists.
I am sure you are aware, but for future readers, there is already a report on Google's Issue Tracker which detail the same kind of behaviour:
Google does seem to know about this issue (the issue has been assigned as of the time of writing this answer). Interestingly, this appears to have been reported in the past here, but was marked as fixed on 2020-08-03.
If you haven't already, I would suggest hitting the ☆ next to the issue number in the top left on both of the previously linked bugs, as this lets Google know more people are encountering this and so it is more likely to be seen to faster.
Upvotes: 3