When running this custom script, docs are created and linked, yet data placeholders remain unchanged. Why is the spreadsheet data not replacing the template values?
function initCustomMenu() {
const ui = SpreadsheetApp.getUi();
ui.createMenu('DocsMaker')
.addItem('Generate Document', 'assembleDocument')
.addToUi();
}
function assembleDocument() {
const baseTemplate = DriveApp.getFileById('TEMPLATE_ID');
const folderTarget = DriveApp.getFolderById('FOLDER_ID');
const dataSheet = SpreadsheetApp.getActive().getSheetByName('Responses');
const dataRows = dataSheet.getDataRange().getValues();
dataRows.slice(1).forEach((record, idx) => {
if (record[6]) return;
let docCopy = baseTemplate.makeCopy(`${record[0]} Record`, folderTarget);
let currentDoc = DocumentApp.openById(docCopy.getId());
let docBody = currentDoc.getBody();
docBody.replaceText('<<Name>>', record[0]);
currentDoc.saveAndClose();
dataSheet.getRange(idx + 2, 7).setValue(currentDoc.getUrl());
});
}