Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

How to send email to a person selected from a dropdown menuwith all answers of a response of the form submission?

$
0
0

I want to notify mentors if they're selected by a user on a Google Form.

The names of the mentors are in a drop-down menu in the Google Form. This is the form: https://forms.gle/iNuA5nB2J9koKhXt6. I'm storing responses in a spreadsheet, I've created a different worksheet in the same spreadsheet named "namenemail" in which I've stored the names and email IDs of the mentors. This is the spreadsheet: https://docs.google.com/spreadsheets/d/15xS_-I6Jw3cqx-00Ink4FFTcfmI3Zi-hBGlMU2x0Cb4/edit?usp=sharing.

I want to send an email to the mentor whose name is selected from the dropdown menu with all the answers from the response of google form submission on submit. I can't seem to get it right.

I found this one script which only works when the question with the dropdown menu is the first question which is not the case in my form. I tried modifying it but I can't seem to get it right. The code also flags an error

TypeError: Cannot read property 'range' of undefined (line 6, file "Code").

Here is the script that I'm using:

function onSubmit(e) {//setup the spreadsheetvar ss = SpreadsheetApp.getActiveSpreadsheet();//get the range from OnFormSubmitvar range = e.range;Logger.log("DEBUG: the range is "+range.getA1Notation());//DEBUG// get the data for the rangevar response = range.getValues();// get the clinician name from the form submissionvar mentor = response[0][2]; Logger.log("DEBUG: Mentor name = "+Name);// DEBUG// get the emails listvar emailSheet =    SpreadsheetApp.getActiveSpreadsheet().getSheetByName("namenemail");// get ALL the data from this sheetvar emaildata = emailSheet.getDataRange().getValues();// check how many rows of datavar emailLastRow = emailSheet.getLastRow();// start the loop through the emails datafor (var i=1; i<emailLastRow; i++){// if the mentor is equal to Emailif (mentor == emaildata[i][0]){  // there is a match  //Next, get the email address  var emailmentor = emaildata[i][1]; Logger.log("DEBUG: clinician = "+emaildata[i][0]+", email address: "+emailmentor);// DEBUG  // Finally, send the Email.  var theirName = e.values[0];  var theirEmail = e.values[1];  var theEnquiry = e.values[4];  var subject = "New Form Submitted";  var message = "New Enquiry by: \n\n EMAIL: "+ theirEmail +" \n Name: "+ theirName +" \n\n Regarding Enquiry: \n"+ theEnquiry; MailApp.sendEmail(emailClinician, subject, message);}}}

Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>