Before anyone says go look at other threads, I already checked out the following: Running Multiple Functions in Google Apps Script and How to execute multiple functions in google apps script in order? and am still stuck.
For reference, I have limited coding experience and have been teaching myself to do this one specific task and a couple other document auto fill app scripts (which work fine but are individual) for my job.
I have a google form for data ingest which auto fills a series of forms needed to complete an application at my company. Previously, you would have to manually input the data multiple times and I figured there had to be a better way.
The code takes inputs from the google form via a spreadsheet so we can keep track and auto fills a 3 pre generated docs which later get synced on to our network drive so all in office can access what they need.
Anyway, the code is as follows:
function fileFills(e){
var address = e.values[1];
var tenman = e.values[2];
var tennum = e.values[3];
var price = e.values[4];
var wks = e.values[5];
var deposit = e.values[6];
var tname1 = e.values[7];
var tname2 = e.values[8];
var tname3 = e.values[9];
var tname4 = e.values[10];
var tname5 = e.values[11];
var tname6 = e.values[12];
var tname7 = e.values[13];
var tname8 = e.values[16];
var tname9 = e.values[17];
var file = DriveApp.getFileById('form template 1');
var parentFolder = DriveApp.getFolderById('main folder');
var newFolder = parentFolder.createFolder(address);
var copy = file.makeCopy(address + ', ' + ' Summary');
copy.moveTo(newFolder);
var doc = DocumentApp.openById(copy.getId());
var body = doc.getBody();
body.replaceText('{{Add}}', address);
body.replaceText('{{TM}}', tenman);
body.replaceText('{{TTC}}', tennum);
body.replaceText('{{Price}}', price);
body.replaceText('{{Time}}', wks);
body.replaceText('{{Deposit}}', deposit);
body.replaceText('{{N1}}', tname1);
body.replaceText('{{N2}}', tname2);
body.replaceText('{{N3}}', tname3);
body.replaceText('{{N4}}', tname4);
body.replaceText('{{N5}}', tname5);
body.replaceText('{{N6}}', tname6);
body.replaceText('{{N7}}', tname7);
body.replaceText('{{N8}}', tname8);
body.replaceText('{{N9}}', tname9);
var file2 = DriveApp.getFileById('form template 2');
var copy2 = file2.makeCopy(address + ', ' + ' Key Sign');
copy2.moveTo(newFolder);
var doc2 = DocumentApp.openById(copy2.getId());
var body2 = doc2.getBody();
body2.replaceText('{{Add}}', address);
body2.replaceText('{{TTC}}', tennum);
body2.replaceText('{{Time}}', wks);
body2.replaceText('{{N1}}', tname1);
body2.replaceText('{{N2}}', tname2);
body2.replaceText('{{N3}}', tname3);
body2.replaceText('{{N4}}', tname4);
body2.replaceText('{{N5}}', tname5);
body2.replaceText('{{N6}}', tname6);
body2.replaceText('{{N7}}', tname7);
body2.replaceText('{{N8}}', tname8);
body2.replaceText('{{N9}}', tname9);
var file3 = DriveApp.getFileById('form template 3');
var copy3 = file3.makeCopy(address + ', ' + ' Tenancy Summary');
copy3.moveTo(newFolder);
var doc3 = DocumentApp.openById(copy.getId());
var body3 = doc3.getBody();
body3.replaceText('{{Add}}', address);
body3.replaceText('{{TM}}', tenman);
body3.replaceText('{{TTC}}', tennum);
}
Obviously I have removed file and folder IDs above.
The issue is that when I submit a test result through the form, it generates a new folder with the correct address, it then copies the first doc into it and fills it, but that is as far as it gets. I get no 2nd or 3rd form.
I had a version previously where I managed to get it to make copies of the 2nd and 3rd form as well, but only into the parent folder and it would not fill the data or move it to the correct folder.
Please help! I am sure its something obvious that I'm missing but it's driving me crazy!
Thanks!