I have a Google form which I use to populate a Google docs from a certain template whenever a new response is submitted. In order to achieve this, I have written this script, but it is not working and showing this error TypeError: Cannot read property 'values' of undefined (line 3, file "Code"):

function createdocs(e) {

  var Contracttype = e.values[1];
  var Partnername = e.values[2];
  var Bankname = e.values[3];
  var Accountnumber = e.values[4];
  var TIN = e.values[5];
  var Bankcode = e.values[6];
  var Businesscode = e.values[7];
  var Phone = e.values[8];
  var Director = e.values[9];
  var Contractstartingdate = e.values[10];
  var Contractendingdate = e.values[11];
  var EmailAddress = e.values[12];

  var file = DriveApp.getFileById('10lZQhmbocTOmvGwklYnHNvXbdGXDmpbgFbvcnu67G7c'); 
  var folder = DriveApp.getFolderById('1O6QJZ5gRRoSUeolcVvKlMe65Wdb4rz9z')
  var copy = file.makeCopy(Partnername + ',' + Contractstartingdate, folder); 
  var doc = DocumentApp.openById(copy.getId()); 
  var body = doc.getBody(); 

  body.replaceText('{{Partner name}}', Partnername);  
  body.replaceText('{{Bank name}}', Bankname);
  body.replaceText('{{Account number}}', Accountnumber);
  body.replaceText('{{TIN}}', TIN);
  body.replaceText('{{Bank code}}', Bankcode);
  body.replaceText('{{Business code}}', Businesscode);
  body.replaceText('{{Phone}}', Phone);
  body.replaceText('{{Director}}', Director);
  body.replaceText('{{Contract starting date}}', Contractstartingdate);
  body.replaceText('{{Contract ending date}}', Contractendingdate);


I have used a youtube tutorial for this purpose and followed every step, But I am failing, how to define values in the script, I have installed the onformSubmit trigger. But there is something going wrong Please help me with this out

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.