UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Send Email Based Of Google Form Option    
 
   
tpitman
post Jun 20 2017, 08:40 AM
Post#1



Posts: 543
Joined: 20-June 04
From: UK


I have a google form where I would like to replace the normal code with send an email to someone based on an option question on the form.


i.e

O Admin
O Teaching
O Facilities


if "Admin" is selected, send notification to a@xyz.ac.UK

If "Teaching" is selected, send notification to b@xyz.com

If "Facilities" is selected, send notification to c@xyz.com

etc


I have found this example, which email to specified person, but I need to send the email based on the selection?


CODE
function sendFormByEmail(e)
{    
  // Remember to replace this email address with your own email address
  var email = "you@example.com";

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

  // The variable e holds all the form values in an array.
  // Loop through the array and append values to the body.

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

  // Insert variables from the spreadsheet into the subject.
  // In this case, I wanted the new hire's name and start date as part of the
  // email subject. These are the 3rd and 16th columns in my form.
  // This creates an email subject like "New Hire: Jane Doe - starts 4/23/2013"
  subject += e.namedValues[headers[2]].toString() + " - starts " + e.namedValues[headers[15]].toString();

  // Send the email
  MailApp.sendEmail(email, subject, message);

  // Based off of a script originally posted by Amit Agarwal - www.labnol.org
  // Credit to Henrique Abreu for fixing the sort order
}
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    24th July 2017 - 01:27 PM