Google workspace add-ons, cats example error: TypeError: Cannot read property 'userTimezone' of undefined

Viewed 124

I am investigating in how to create Google Workspace add-ons and I am following the cats quickstart

But running it I encounter this error "TypeError: Cannot read property 'userTimezone' of undefined" on Common.gs row 24

var hour = Number(Utilities.formatDate(new Date(), e.userTimezone.id, 'H'));

The function that contains this row is

function onHomepage(e) {
  console.log(e);
  var hour = Number(Utilities.formatDate(new Date(), e.userTimezone.id, 'H'));
  var message;
  if (hour >= 6 && hour < 12) {
    message = 'Good morning';
  } else if (hour >= 12 && hour < 18) {
    message = 'Good afternoon';
  } else {
    message = 'Good night';
  }
  message += ' ' + e.hostApp;
  return createCatCard(message, true);
}

Can anyone help me to understand where is the problem ?

Thanks in advance, Vincenzo

2 Answers

I came across the same problem too. Tried to deploy after encountering this message, I was able to install the app :)

It's straight forward but like many things, not obvious!

You need to run the script once in order to set up the requisite permissions. It doesn't actually run the script but presents you with the option to agree to authorize the script. Once you have authorized the script, you cannot run it from the console because there will be no event(e) available at this time, hence the e.userTimezone.id error you encountered.

Now you will be able to install the add-on. Refresh Gmail and you will be good to go. Look for the cat paw icon over to the right of your screen.

Related