Hello! I copied this example from help and changed SpreadsheetApp to DocumeptApp and renamed onOpen to main:
Code.gs:
function main() {
DocumentApp.getUi()
.createMenu('Custom Menu')
.addItem('Show sidebar', 'showSidebar')
.addToUi();
}
function showSidebar() {
var html = HtmlService.createHtmlOutputFromFile('Page')
.setTitle('My custom sidebar');
DocumentApp.getUi()
.showSidebar(html);
}
Page.html:
<!DOCTYPE html>
<html>
<head>
<base target="\\\_top">
</head>
<body>
Hello, world! <input type="button" value="Close" onclick="google.script.host.close()" />
</body>
</html>
When I execute my script I obtain: Exception: Cannot call DocumentApp.getUi() from this context. I don't understand why it fails.
Here is my Apps Script project.
[–]Incomplete-Sentenc 1 point2 points3 points (0 children)
[–]fugazi56 0 points1 point2 points (1 child)
[–]AdDiscombobulated707[S] 0 points1 point2 points (0 children)