If you get the data returned as an array, you can check for existing values with the JavaScript indexOf()
method.
- Get the data from the spreadsheet
- Use the value to be written to check for existing value
- If value exists inform you.
Get the Data
Google Documentation - Get Values
// The code below will get the values for the range C2:G8
// in the active spreadsheet. Note that this will be a javascript array.
var values = SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 4).getValues();
Logger.log(values[0][0]);
Check For Duplicate:
var returnFromIndexOf = values.indexOf(valueToChk);
Inform you:
if (values.indexOf(valueToChk) != -1) {
//Send me an email
// Send an email with two attachments: a file from Google Drive (as a PDF) and an HTML file.
var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
var blob = Utilities.newBlob('Insert any HTML content here', 'text/html', 'my_document.html');
MailApp.sendEmail('mike@example.com', 'Attachment example', 'Two files are attached.', {
name: 'Automatic Emailer Script',
attachments: [file.getAs(MimeType.PDF), blob]
});
};
Google Documentation - Send Email
You need to install Google Forms to your Google Drive in order to create a new form.
Google Site - Google Forms
There are ways to run some code when the form is submitted. You can run an event from either your spreadsheet or the form attached to the spreadsheet when the form is submitted.
In the Apps Script Code editor, open the Resources menu and add a trigger to run a function with the form is submitted.