I am working on a form that takes values and puts them in a spreadsheet. I want to take the values from that spreadsheet and use them as replacements in a sheet (with the intent of saving to .pdf, which I will learn next)
Here is a snippet of my code. I was expecting the values in the {{}} to be replaced with the values from the spreadsheet. It’s not happening though. It NAMES the document appropriately, but I think I’m using the wrong function call for the body.
function createNewGoogleDoc(){
const googleDocTemplate = DriveApp.getFileById('<myTemplateID>');
const destinationFolder = DriveApp.getFolderById('<myFolderID>');
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form Responses 1');
const rows = sheet.getDataRange().getValues()
rows.forEach(function(row,index){
if (index === 0) return; //using strict equality check to see if this is the header row. If so, pass.
if (row[38]) return;//38
const copy = googleDocTemplate.makeCopy(`${row[4]}`+''s Service Contract',destinationFolder);
const doc = DocumentApp.openById(copy.getId())
const body = doc.getBody().replaceText();
//const friendlyDate = new Date(row[31]).toLocaleDateString();
//const friendlyDate2 = new Date(row[32]).toLocaleDateString();
body.replaceText(`{{Email}}`, `${row[1]}`); <--- this here.