setting up script to include google docs form data in email notification

user1872449 picture user1872449 · Dec 3, 2012 · Viewed 15.2k times · Source

I've setup a form using googledocs. I just want to have the actual data entered into the form emailed to me, as opposed to the generic response advising that the form has been completed.

I have no skill or experience with code etc, but was sure i could get this sorted. I've spent hours+hours and haven't had any luck.

My form is really basic.it has 5 fields. 4 of which are just text responses, and one multiple choice.

I found this tute online (http://www.labnol.org/internet/google-docs-email-form/20884/) which i think sums up what i'm trying to do, but have not been able to get it to work.

from this site i entered the following code:

function sendFormByEmail(e) 
{    
  var email = "[email protected]"; 

  var subject = "Google Docs Form Submitted";  

  var s = SpreadsheetApp.getActiveSheet();
  var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];    
  var message = "";    

 for(var i in headers)
message += headers[i] + ' = '+ e.namedValues[headers[i]].toString() + "\n\n"; 

  MailApp.sendEmail(email, subject, message); 
}

To this, i get the following response: ->

Your script, Contact Us Form Mailer, has recently failed to finish successfully. A summary of the failure(s) is shown below. To configure the triggers for this script, or change your setting for receiving future failure notifications, click here.

The script is used by the document 100% Club.

Details:

Start               Function        Error Message                                                       Trigger     End
12/3/12 11:06 PM    sendFormByEmail TypeError: Cannot call method "toString" of undefined. (line 12)    formSubmit  12/3/12 11:06 PM

Is anyone able to help shed some light on this for me? I'm guessing i'm not including some data neeeded, but i honestly have no clue.

Answer

Palani picture Palani · Jan 29, 2013

Workaround http://www.labnol.org/internet/google-docs-email-form/20884/ You have to setup app script to forward the data as email.