I have a current script in Google Docs that adds a header with collapsible list beneath it (on a pageless setup) underneath a specific section of the document.
I am looking for users to be able to trigger the script from within the document. I have been able to achieve this in Google Spreadsheets using links and Drawings (and using a custom menu, but that’s less ideal in this instance), but have not been able to achieve the same thing within Google Docs.
Ideally, a user would click a link, which would trigger the script that adds the following:
Here’s the script I have so far:
function insertText() {
var header = "Enter_Item_Title_Here"
var bulletOneHeader = "Agenda Item Owner(s): ___________"
var bulletTwoHeader = "Discussant: ___________"
var bulletThreeHeader = "Discussion Date: ___________"
var bulletFourHeader = "External follow up: ___________"
var bulletFiveHeader = "Notes: ___________"
var bulletSixHeader = "Action Items: ___________"
var cursor = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();
var pr = cursor.findText("New Items:").getElement().getParent();
var i = cursor.getChildIndex(pr) + 1;
cursor.insertParagraph(i, header).setHeading(DocumentApp.ParagraphHeading.HEADING3);
cursor.insertListItem(i + 1, bulletOneHeader).setGlyphType(DocumentApp.GlyphType.BULLET).setAttributes({ [DocumentApp.Attribute.BOLD]: true });
cursor.insertListItem(i + 2, bulletTwoHeader).setGlyphType(DocumentApp.GlyphType.BULLET).setAttributes({ [DocumentApp.Attribute.BOLD]: true });
cursor.insertListItem(i + 3, bulletThreeHeader).setGlyphType(DocumentApp.GlyphType.BULLET).setAttributes({ [DocumentApp.Attribute.BOLD]: true });
cursor.insertListItem(i + 4, bulletFourHeader).setGlyphType(DocumentApp.GlyphType.BULLET).setAttributes({ [DocumentApp.Attribute.BOLD]: true });
cursor.insertListItem(i + 5, bulletFiveHeader).setGlyphType(DocumentApp.GlyphType.BULLET).setAttributes({ [DocumentApp.Attribute.BOLD]: true });
cursor.insertListItem(i + 6, bulletSixHeader).setGlyphType(DocumentApp.GlyphType.BULLET).setAttributes({ [DocumentApp.Attribute.BOLD]: true });
}
Here’s an example google doc that includes the script I have so far.
I’ve been looking at and playing around with this existing question and also this one, but haven’t been able to figure it out.