Andrew C
Andrew C

Reputation: 21

“Cannot call DocumentApp.getUi() from this context.”

I can't run the code and I don't get what's wrong with it.

function onOpen(a) {
    var ui = DocumentApp.getUi() // ..
}

How it looks like

Error:

Cannot call DocumentApp.getUi() from this context. (line 2, file "Code")

Upvotes: 1

Views: 2250

Answers (1)

Cooper
Cooper

Reputation: 64140

This works in a Spreadsheet: function onOpen(e) { SpreadsheetApp.getUi().alert('Hello')}

This works in a Document: function onOpen(e) { DocumentApp.getUi().alert('Hello'); }

I would move the onOpen(e) function definition out of the onInstall(e) function definition.

Upvotes: 4

Related Questions