简体   繁体   中英

Google Sheets Email script

Scripting question.

We have a form that inserts the data into a response sheet. Inside the response sheet, we have a script that emails to a set group of people.

Script-

  */ function Initialize() { try { var triggers = ScriptApp.getProjectTriggers(); for (var i in triggers) ScriptApp.deleteTrigger(triggers[i]); ScriptApp.newTrigger("EmailGoogleFormData") .forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet()) .onFormSubmit().create(); } catch (error) { throw new Error("Please add this code in the Google Spreadsheet"); } } function EmailGoogleFormData(e) { if (!e) { throw new Error("Please go the Run menu and choose Initialize"); } try { if (MailApp.getRemainingDailyQuota() > 0) { // You may replace this with another email address var email = "THIS IS WHERE THE EMAIL ADDRESS GOES...REMOVED FOR PRIVACY"; // Enter your subject for Google Form email notifications var subject = "Copier Service Request"; var key, entry, message = "", ss = SpreadsheetApp.getActiveSheet(), cols = ss.getRange(1, 1, 1, ss.getLastColumn()).getValues()[0]; // Iterate through the Form Fields for (var keys in cols) { key = cols[keys]; entry = e.namedValues[key] ? e.namedValues[key].toString() : ""; // Only include form fields that are not blank if ((entry !== "") && (entry.replace(/,/g, "") !== "")) message += key + ' :: ' + entry + "\\n\\n"; } MailApp.sendEmail(email, subject, message); } } catch (error) { Logger.log(error.toString()); } } 

However, What I also need is that when the form is submitted, in some way shape or form, it will send an email to a specified user. This could possibly be specified in the form itself, or via a pop-up. It does not matter. However, my skills in getting it to email a user, specified while filling out the form are lacking. That is just above my knowledge.

I am thinking the easiest way is to keep the code, but inside the email address variable, add another variable that is filled in through a certain selection in the form itself. Like, if I typed in randomemail@gmail.com under an "Email" section, it would find that address, and insert itself into the variable in the email address section.

这是相当容易实现的,因为一旦将表单提交触发器添加到表单中,您已经拥有了很多基础结构。

email = email + "," + e.namedValues["Email"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM