1

I am writing AppScript to develop an Add On to allow user to move the current thread under a label. For the purpose of fetching current thread id.

BuildAddOn(e)

function buildAddOn(e) {
  // Activate temporary Gmail add-on scopes.
  var accessToken = e.messageMetaData.accessToken;
  GmailApp.setCurrentMessageAccessToken(e.messageMetadata.accessToken);

  var messageId = e.messageMetadata.messageId;

While I try to run the function, the following error comes:

TypeError: Cannot read property "messageMetaData" from undefined. (line 3, file "Code")

Mikhail Kholodkov
  • 23,642
  • 17
  • 61
  • 78
Shrimantee Roy
  • 317
  • 3
  • 10

1 Answers1

1

Calling the buildAddOn somewhere else in your code will cause the error. In this context, e is an object that will be passed only during initialization. And this is not equivalent to the object that you see in action handlers.

Sorry, if I misunderstood your question.

hhsb
  • 560
  • 3
  • 23
  • Thanks for the insight. The fault was actually a typo. – Shrimantee Roy Jun 12 '18 at 14:37
  • No , after correcting the typo, when the buildAddOn(e) is run, the error: "TypeError: Cannot read property "messageMetaData" from undefined " remains. When I publish the add on by Deploy from manifest, the error: "TypeError: Cannot read property "accessToken" from undefined." appears on the add on card. – Shrimantee Roy Jun 12 '18 at 22:58
  • Can you log `e` and check its contents? – hhsb Jun 13 '18 at 05:09