I am having trouble connecting my spreadsheet data to my google forms in Apps Script.
function createNewGoogleDocs() {
const googleDocTemplate = DriveApp.getFileById('1cP4N0ueMAG2YNv23epsCpHNHXYZQRV0MqErmOahV9vk');
const destinationFolder = DriveApp.getFolderById('1bFfhSL5qWnbfiaNrn1qPIRn5fx6odkaN')
const sheet = SpreadsheetApp
.getActiveSpreadsheet()
.getSheetByName('Onboarding')
const rows = sheet.getDataRange().getValues();
rows.forEach(function(row, index){
if (index === 0) return;
if (row[20]) return;
const copy = googleDocTemplate.makeCopy(`${row[2]} ${row[1]} č. ${row[5]} (Experiement)` , destinationFolder)
const doc = DocumentApp.openById(copy.getId())
const body = doc.getBody();
const listArray = ["{{}}","{{Forename}}","{{Middle Name}}","{{Surname}}","{{Business Name}}","{{Business Address}}","{{Post Code}}","{{Business Phone Number}}","{{Email}}","{{Website URL}}","{{Website Platform/Username and Password}}","{{Facebook Ad ID}}","{{Facebook Business ID}}","{{Link to Google Drive}}","{{Additional/Important URLs}}","{{Facebook Login}}","{{Facebook Password}}","{{Instagram Login}}","{{Instagram Password}}"]
for (let i in listArray){
if (row[i] == ""){
body.findText(listArray[i]).getElement().getParent().removeFromParent();
} else {
body.replaceText(listArray[i],row[i]);
}
}
doc.saveAndClose();
const url = doc.getUrl();
sheet.getRange(index + 1, 20).setValue(url)
})
}
Providing me with this response...
TypeError: Cannot read property 'getDataRange' of null createNewGoogleDocs @ Onboarding to Form.gs:7