I wanted to the question as formulated in the title, let me elaborate further. I selected the response destination from Forms into a new spreadsheet. Using Google Script I created an add-on (named AutoFill Docs) for this spreadsheet and it "fills out" the Docs template I made and saves itself as a new, separate Docs file in a designated folder.
function onOpen() {
const ui = SpreadsheetApp.getUi();
const menu = ui.createMenu('AutoFill Docs');
menu.addItem('Create New Docs', 'createNewGoogleDocs')
menu.addToUi();
}
function createNewGoogleDocs() {
const Responses = DriveApp.getFileById('XXXXX');
const destinationFolder = DriveApp.getFolderById('XXX')
const sheet = SpreadsheetApp
.getActiveSpreadsheet()
.getSheetByName('Data')
const rows = sheet.getDataRange().getValues();
rows.forEach(function(row, index){
//skipping header
if (index === 0) return;
//Using the row data in a template literal, making a copy of template document in destinationFolder
const copy = Responses.makeCopy(`${row[1]}, ${row[0]} XXXX (XXXX)` , destinationFolder)
const doc = DocumentApp.openById(copy.getId())
const body = doc.getBody();
//replacing my replacement tokens with values from the spreadsheet row
body.replaceText('{{Timestamp}}', row[0]);
body.replaceText('{{Whats your name?}}', row[1]);
//end so on
doc.saveAndClose();
const url = doc.getUrl();
//making documents links
sheet.getRange(index + 1, 16).setValue(url)
})
}
My issue is, that I want all those filled-out templates for every response to save in one docs file (e.g. one response=one new extra page), rather than a new doc file. Of course, I can include links to those docs in the final one or copy and paste, but I prefer it to be automatic.
So here are my concerns: Is it even possible? If yes, how should I modify my existing code to do that or what should I look for?
P.S. I know the "createNewGoogleDocs" is basically the opposite of what I want, but this is the only function I managed to find, but it is just a partial solution to my case. I am a complete newbie, so any guidance/suggestions are very much appreciated, I'm completely stuck.