I have this Google Script where I am creating a document using a template table that lives in another document.
The new document will have a number of small tables (like cards) in it. The code bellow works fine for 100, 200 tables and it finishes in less than 10 seconds. But it fails for more than 500 tables. There is no error message in the Executions window.
I have tried the saveAndClose() function (commented out) but the error continues and it just takes longer to run.
I ran out of ideas how to fix that. Any help or ideas will be appreciated.
function insertSpecification_withSection(){
startTime = new Date()
console.log("Starting Function... ");
// Retuns a Table Template Copied from another Document
reqTableItem = RequirementTemplate_Copy();
// Creates X number of separated tables from the template
for (var i = 0; i < 500; i++){
table = DocumentApp.getActiveDocument().getBody().appendTable(reqTableItem.copy());
// if((i % 100) === 0) {
// DocumentApp.getActiveDocument().saveAndClose();
// }
//
}
endTime = new Date();
timeDiff = endTime - startTime;
console.log("Ending Function..."+ timeDiff + " ms");
}
function RequirementTemplate_Copy() {
//---------------------------------------------------------------------------------------------------------------------------------------------------
var ReqTableID = PropertiesService.getDocumentProperties().getProperty('ReqTableID');
try{
var templatedoc = DocumentApp.openById(ReqTableID);
} catch (error) {
DocumentApp.getUi().alert("Could not find the document. Confirm it was not deleted and that anyone have read access with the link.");
//Logger.log("Document not accessible", ReqTableID)
}
var reqTableItem = templatedoc.getChild(1).copy();
//---------------------------------------------------------------------------------------------------------------------------------------------------
return reqTableItem
}


for (var i = 0; i < 500; i++){ DocumentApp.getActiveDocument().getBody().appendTable(reqTableItem); }minimal reproducible example should includeRequirementTemplate_Copy()for (var i = 0; i < 500; i++){ DocumentApp.getActiveDocument().getBody().appendTable(reqTableItem.copy()); }I still get the errorRequirementTemplate_Copy()