I have a Sheet that is linked with a basic Google form. I want to be able to select a name from the form and once submitted, it automatically send to an address based on the conditions I define. E.g., if Ronald McDonald is selected in the form, then the script says that it should send to [email protected]
The addresses are NOT within the form. - Just the names. I'd like the script to contain the addresses.
This is the first thing I'm attempting to build with app script. I can't find much online to figure out where to start.
Would very much like some help.
To go further, we can select the informations you need and put them inside a well-formatted table.
CodePudding user response:
Try this:
function onFormSubmit(e) {
const eobj = {"Ronald McDonald":"[email protected]","Fred Smith":"[email protected]"};
if(eobj.hasOwnProperty(e.values[1])) {
GmailApp.sendEmail(eboj[e.values[1]],"Subject","Message")
}
}
function createOnFormSubmitTrigger() {
if(ScriptApp.getProjectTriggers().filter(t => t.getHandlerFunction() == "onFormSubmit").length == 0) {
ScriptApp.newTrigger("onFormSubmit").forSpreadsheet(SpreadsheetApp.getActive()).onFormSubmit().create();
}
}
You will have to fill in the eobj with all the the names as properties and values as email addresses.