In an attempt to reduce hours of repetitive labor, I've tried to create a Google app script that appends various template documents in sequence. The method for doing this uses Google DocumentApp to append various elements from multiple template documents to a single new document. This works with all element types except List Items.
The DocumentApp copies list items from one GDoc to another but the new bullets appear with no visible glyph/bullet/number and there are various formatting issues. I've tried manually setting the Glyph Type, as recommended by similar SO posts, but the indentation has issues -- when you adjust the indent on the new bullet, it does not follow the usual pattern of shift in/shift out when clicking tab/shift-tab. When simply using appendListItem, the invisible glyph outcome is not consistent.
When copying the template GDocs to a newly created GDoc, the glyphs do not appear. When copying to an already existing GDoc (tested multiple times using docs with unknown and inconsistent usage history), the glyphs sometimes appear. I suspect the issue is with the appendListItem() or .copy() -- both are used in the script:
An excerpt from the script being used:
thisBody.appendListItem(templateBody.getChild(i).copy());
I've spent hours researching workarounds and causes for this issue to no avail. It seems to be a known issue that has not been resolved. Please advise. Is there some mistake I'm making?
Respectfully, -J
Full code below:
function appendTemplate(templateID) {
var thisDoc = DocumentApp.getActiveDocument();
var thisBody = thisDoc.getBody();
var templateDoc = DocumentApp.openById(templateID); //Pass in id of doc to be used as a template.
var templateBody = templateDoc.getBody();
// Insert a Page Break between sections
thisBody.appendPageBreak();
// Append all body sections
// Reference: https://stackoverflow.com/questions/54817801/google-docs-script-to-insert-another-document
for(var i=0; i<templateBody.getNumChildren();i++){ //run through the elements of the template doc's Body.
switch (templateBody.getChild(i).getType()) { //Deal with the various types of Elements we will encounter and append.
case DocumentApp.ElementType.PARAGRAPH:
thisBody.appendParagraph(templateBody.getChild(i).copy());
break;
case DocumentApp.ElementType.LIST_ITEM:
thisBody.appendListItem(templateBody.getChild(i).copy());
break;
case DocumentApp.ElementType.TABLE:
thisBody.appendTable(templateBody.getChild(i).copy());
break;
case DocumentApp.ElementType.INLINE_IMAGE:
thisBody.appendImage(templateBody.getChild(i).copy());
break;
}
}