I am trying to auto send an email when a new respond from Google Form.
I have a template from Google Doc, a Form and a Sheet from the form respond. I copied a script as below:
function autoFillGoogleDocsFromForm(e) {
var hoten = e.values[1];
var sodienthoai = e.values[2];
var ngaysinh = e.values[3];
var image = e.values[4];
var templateFile = DriveApp.getFileById("162v26_K5qXXV-6f-yahRfPpfdlO5tkYDD3WvoZ2RChI");
var templateResponseFolder = DriveApp.getFolderById("1sr5_LtzKb16MX_nXX9Bdcq6UacPadWg");
var copy = templateFile.makeCopy('Ho va Ten ' + HoTen, templateResponseFolder);
var doc = DocumentApp.openById(copy.getId());
var body = doc.getBody();
body.replaceText("{{HoTen}}", hotenoTen);
body.replaceText("{{Sdt}}", sodienthoai);
body.replaceText("{{Birthday}}", ngaysinh);
body.replaceText("{{ImageUrl}}", image);
doc.saveAndClose();
}
But when I run the code, an error was show up:
TypeError: Cannot read properties of undefined (reading 'values')
autoFillGoogleDocsFromForm @ Code.gs:2
I watched videos on Youtube but don’t know why It is wrong.
Can someone please explain to me why? and how to solve this?
New contributor
Mai Phước Hoàng is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.