I created a google form and the form is working fine. We were manually using that information to fill another form on paper and now I'm trying to automate it.
Here's the process I used -
Created a google form
In the response spreadsheet of the google form I opened the Apps Script under the Extensions tab and wrote the following code that I got from youtube
function CHALLANDETAILS(e) {
var Timestamp = e.values[0];
var CHALLANNUMBER = e.values[2];
var VEHICLENUMBER = e.values[3];
var PARTYNAME = e.values[4];
var DESCRIPTION = e.values[5];
var QUANTITY = e.values[6];
var WEIGHT = e.values[7];
var templateFile = DriveApp.getFileById("1G6SMzSmSl50rmz_zJizUFYUopcdLf3GsnauRMtYwk18");
var templateResponseFolder = DriveApp.getFolderById("1RTJ2CIwU-bYXVNTGQzUyiwpPdaYceWH5");
var copy = templateFile.makeCopy(PARTYNAME + ',' + CHALLANNUMBER, templateResponseFolder);
var doc = DocumentApp.openById(copy.getID());
var body = doc.getBody();
body.replaceText("{{DATE & TIME}}", Timestamp);
body.replaceText("{{G.P No}}", CHALLANNUMBER);
body.replaceText("{{VEHICLE NO}}", VEHICLENUMBER);
body.replaceText("{{M/s}}", PARTYNAME);
body.replaceText("DESCRIPTION", DESCRIPTION);
body.replaceText("{{QUANTITY}}", QUANTITY);
body.replaceText("{{WEIGHT}}", WEIGHT);
doc.saveAndClose();
}
I then added the trigger with the following selections function to run - CHHALLANDETAILS run at deployment - head event source - from spreadsheet event type - on form submission failure - notify me immediately
When I tried to run the code, it gave the following error:
e: undefined
Timestamp: undefined
CHALLANNUMBER: undefined
VEHICLENUMBER: undefined
PARTYNAME: undefined
DESCRIPTION: undefined
QUANTITY: undefined
WEISHT: undefined
templateFile: undefined
templateResponseFolder: undefi
copy: undefined
doc: undefined
body: undefined
I have double checked the placeholders and replacement texts and everything matches but the code won't work without errors.
When I filled a test form, it created a new doc in the right folder and copied the format of the old doc but did not replace the placeholders with the form data. So essentially it created the copy of template and nothing else.
The script is working partially I believe as its creating new doc as per template but it isn't reading the variables and replacing the placement text with them
Following your steps, you might be wrongly getting value var CHALLANNUMBER = e.values[2]; so first column Timestamp is fit to e.values[0] and second column in your case CHALLANNUMBER is fit to e.values[1]
from google spreadsheet but this script will create new google doc on every form submission because you are copying document here:
but I think you want to store all responses into one google doc. So if you want to store all responses into one google doc on tabular format you need to change script to this:
Also you need to create table in your template google doc file. Hope this helps.