0

I used Google's Quickstart: Add-on for Google Forms to enable e-mail notifications for respondents of my form. I also added a few lines to send unique code to each respondent and I would like to have these codes stored in responses sheet.

The code below sends the message with code, but it doesn't store code in responses sheet.

function sendRespondentNotification(response) {
  var form = FormApp.getActiveForm();
  var settings = PropertiesService.getDocumentProperties();
  var emailId = settings.getProperty('respondentEmailItemId');
  var emailItem = form.getItemById(parseInt(emailId));
  var respondentEmail = response.getResponseForItem(emailItem)
      .getResponse();
  if (respondentEmail) {
    var template =
        HtmlService.createTemplateFromFile('RespondentNotification');
    template.paragraphs = settings.getProperty('responseText').split('\n');
    template.kod = (new Date).getTime().toString(16).substring(5);
    template.notice = NOTICE;
    var message = template.evaluate();
    MailApp.sendEmail(respondentEmail,
        settings.getProperty('responseSubject'),
        message.getContent(), {
          name: form.getTitle(),
            htmlBody: message.getContent()
        });
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheets()[0];
    var LastRow = sheet.getLastRow();
    var cell = sheet.getRange(LastRow, 5);
    cell.setValue(template.kod);    
  }
}
  • possible duplicate of [Send form by email and track responses in spreadsheet](http://stackoverflow.com/questions/18668828/send-form-by-email-and-track-responses-in-spreadsheet) – Mogsdad Jul 11 '15 at 17:47
  • My situation is a bit different. I need to send email after the typical google form is submitted and then add one more info in the spreadsheet. In the link you posted data was collected via email. – Pawel Mucha Jul 11 '15 at 18:37
  • Adapt the code to that. – Mogsdad Jul 11 '15 at 19:19

1 Answers1

0

you could use onFormSubmit to generate the unique id and include it in the email for a webapp to use. that id could be something simple like the row number of the response (not in e.values thou) or generate on the fly and write to the responses spreadsheet as a new column. adding columns does not break the form.

Zig Mandel
  • 19,571
  • 5
  • 26
  • 36