Trying to insert specific text at my cursor to a Google Doc via a custom menu created via Google Apps Script. I am then trying to format that text to specific headings, body, etc. The below code is not working and is inserting all text with the same format as the surrounding text within the Google Doc. I have tried a number of different methods to accomplish this but am hoping for some help or tips!
function menuItem2() {
var cursor = DocumentApp.getActiveDocument().getCursor();
var headerAttr = {}
headerAttr[DocumentApp.Attribute.HEADING] = DocumentApp.ParagraphHeading.HEADING2;
var goLiveHeader = cursor.insertText("Go Live Process");
goLiveHeader.editAsText().setAttributes(0, goLiveHeader.getText().length, headerAttr);
DocumentApp.getUi().alert('Resources added.');
}