1

Is it possible to somehow distinguish between the first submission of google form and remaining submissions of same form where user is just updating his previous response?

I have used onSubmit trigger where email notifications are sent every time user submits a form. The problem is that the same email is triggered when the same user updates his form (i.e. when he's made a mistake). I would like to either stop these emails to being sent on update or change the email message?

Can you please suggest if it is possible to achieve this? I think onChange(e) might work.

user5711693
  • 113
  • 5
  • 17

1 Answers1

1

In the sheet that collects form submissions, the edited entries have a note "Responder updated this value". The script can get these notes; if at least one is nonempty, then it's an edit. Here is an example of a script (to be triggered by form submission) that sends different emails for new and edited entries.

function notify(e) {
  if (e.range.getNotes()[0].join('')) {
    MailApp.sendMail('me@example.com', 'updated entry', 'user edited submission');
  }
  else {
    MailApp.sendMail('me@example.com', 'new entry', 'user submitted form');
  }
}
  • Thank you for your answer. If I want to update a note of a particular cell, can I do e.range.getNotes()[0][1] to match it to "Responder updated this value" and if it has been updated to that, set the note to a particular value? I tried it and I get undefined when I use logger.log to output this "e.range.getNotes()[0][1]" Do you know why this is the case? – user5711693 May 22 '16 at 21:41
  • If the function is triggered by form submission, it receives event object (named `e` here). If you were trying to run it directly, `e` would be undefined. –  May 22 '16 at 21:43
  • The function is triggered by form submission, so that's why I am not sure why I get undefined. In logs, I am outputting this: Logger.log("testing 1" + e.range.getNotes()[0][1]); Logger.log("testing 2" + e.range.getNotes()[0][2]); Logger.log("testing 3" + e.range.getNotes()[0][3]); The first one outputs correct value but the next two give "undefined". Any idea why this is the case? – user5711693 May 22 '16 at 22:35
  • When I see that `e.range.getNotes()[0][2]` is undefined, my reaction is to log `e.range.getNotes()[0]` to check how many entries it has. –  May 22 '16 at 22:36
  • There are 3 entries, it might be the index - I will try outputting everything and see if that is the reason. Is there any other reason for getting undefined apart from above mentioned reason? – user5711693 May 22 '16 at 22:46
  • If there are three entries, they would be [0][0], [0][1], and [0][2]. The only reason for getting undefined is that something is not defined. –  May 22 '16 at 22:49