Hoping I can get some advice on this. I'm using scripts to automate the creation of a document, where the data comes from an existing google doc. After no luck using linked tables, I'm trying to insert a table at a point identified by search text in the document.
For example, I'd search for TABLE1HERE in the document and replace it with a table defined by [[Heading,Data],[Heading2,MoreData]]
. I've tried the below code and a number of variations with no luck. Any pointers would be fantastic.
function updateTablesTEST(searchText,replacementTable){
var document = DocumentApp.getActiveDocument();
var documentBody = document.getBody();
var textLocation;
var newPosition;
var textChild;
textLocation = documentBody.findText(searchText).getElement();
textChild = textLocation.getParent().getChildIndex(textLocation);
documentBody.insertTable(textChild+1, replacementTable);
}