I sometimes need to temporarily write something in somewhere. I make a 'Temp' google doc, every times I use it I need to remove the content previously there. I want to make a google apps script to add a button to remove all content and format in doc. I try the following code:
function onOpen() {
DocumentApp.getUi()
.createMenu("Clear")
.addItem("Clear", "dialogs")
.addToUi();
}
function dialogs() {
var ui = DocumentApp.getUi();
var result = ui.alert(
"Please Confirm",
"Are you sure you want to clear the document?",
ui.ButtonSet.YES_NO);
if (result == ui.Button.YES) {DocumentApp.getActiveDocument().getBody().clear()}
}
However it doesn't work. How to fix that?