So I’m using this reference (Google Form Search and Pull Spreadsheet Data) and it works….however right now it sends 3 emails with the same info. What needs to change in this to ONLY send one email?
The only values it’s pulling from the Google Sheet is a lookup of the Shipping ID (Column A) the Status of the order (Column B) and what email to send this to (Column C). I have also tried adding additional variables and this script below then sends it based on the same number of variables I added. So if I have 7 var’s it sends 7 emails. I tried moving the Mailapp.sendEmail out of the if (found) but that didn’t solve anything. I’m stumped.
function installTrigger() {
// This function instructs the program to trigger the checkID function whenever a form response is submitted
ScriptApp.newTrigger('checkID')
.forForm(FormApp.getActiveForm())
.onFormSubmit()
.create();
}
function checkID(e) {
// This function will parse the response to use the customer ID to retrieve email address and shipping status from the Spreadsheet Database
var responses = e.response.getItemResponses(); // Gets the form responses
var id = responses[0].getResponse(); // Assuming the first answer (index 0) is the customer ID)
var found = SpreadsheetApp.openById('spreadsheet_id')
.getRange('Sheet1!A1:C8') // The spreadsheet cells range in A1 Notation
.getValues() // Retrieve their values in rows
.filter((row) => row[0] == id); // Filter the rows for the provided customer ID
if (found) {
var status = found[0][1]; //Column B
var email = found[0][2]; //Column C
var subject = "Shipping Status";
var message =
`Hello!
The status of the order number ${id} is: ${status}.`
MailApp.sendEmail(email, subject, message);
}
}
2