I'm getting the error We're sorry, a server error occurred. Please wait a bit a try again on the getCursor() line.
Here's the code. It's very simple.
function onOpen() {
DocumentApp.getUi() // Or DocumentApp or FormApp.
.createMenu('Checkbox')
.addItem('Insert Checkbox', 'insertCheckbox')
.addToUi();
}
function insertCheckbox() {
var cursor = DocumentApp.getActiveDocument().getCursor(); // CODE BREAKS HERE
if (cursor) {
// Attempt to insert text at the cursor position. If the insertion returns null, the cursor's
// containing element doesn't allow insertions, so show the user an error message.
var element = cursor.insertText('ಠ‿ಠ');
if (element) {
element.setBold(true);
} else {
DocumentApp.getUi().alert('Cannot insert text here.');
}
} else {
DocumentApp.getUi().alert('Cannot find a cursor.');
}
}
Any thoughts?
Thanks in advance.