0

I have the script below to create Google docs from a template when a form response is submitted. But this scripts uses only one template. What I want is to create different docs depending on the response of the first question of the form. The other responses should replace the given words in the templates. But I am having a bit difficulties to reach this result. Is there any way of doing so?

function createdocs(e) {
  var dataRange = SpreadsheetApp.getActiveSheet().getDataRange()
  var data = dataRange.getValues();
  var headers = data[0];

  for (var row=1; row < data.length; row++) {
    var e = {};
    e.values = data[row];
}
  var Contracttype = e.values[1];
  var Partnername = e.values[2];
  var Address = e.values[3]
  var Bankname = e.values[4];
  var Accountnumber = e.values[5];
  var TIN = e.values[6];
  var Bankcode = e.values[7];
  var Businesscode = e.values[8];
  var Phone = e.values[9];
  var Director = e.values[10];
  var Contractstartingdate = e.values[11];
  var Contractendingdate = e.values[12];
  var EmailAddress = e.values[13];

  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('{{Address}}', Address);  
  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);

  doc.saveAndClose();
}

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.