Skip to content

Instantly share code, notes, and snippets.

@thinkallabout
Created July 11, 2019 04:19
Show Gist options
  • Save thinkallabout/27848ad6fca960de013726a3ea6c3b03 to your computer and use it in GitHub Desktop.
Save thinkallabout/27848ad6fca960de013726a3ea6c3b03 to your computer and use it in GitHub Desktop.
Inquiry Form Submission - Decoupage Dreams - Google Apps Script
// Adds an email to sheet.
function addEmailToSheet(email) {
var sheetsApp = SpreadsheetApp.getActiveSpreadsheet();
// 05/2019 for example..
var monthString = (new Date().getMonth() + 1).toString();
if(monthString.length == 1) {
monthString = "0" + monthString;
}
var sheetName = monthString + "/" + new Date().getYear();
// Get or create sheet.
var sheet = sheetsApp.getSheetByName(sheetName);
if(sheet == null) {
sheet = sheetsApp.insertSheet(sheetName);
sheet.appendRow(['Email Address', 'Date']);
sheet.setFrozenRows(1);
sheet.setColumnWidth(1, 300)
sheet.setColumnWidth(2, 140)
sheet.deleteColumns(3, 24);
sheet.getRange(1, 1).setFontWeight("bold")
sheet.getRange(1, 2).setFontWeight("bold");
}
sheet.appendRow([email, new Date()]);
}
function testAddEmailToSheet() {
var testEmail = "[email protected]";
addEmailToSheet(testEmail);
}
function doGet(e) {
var email = e.parameter.email;
if(email == null || email == undefined) {
console.error("Email not provided.");
return ContentService.createTextOutput("Email not provided..");
}
addEmailToSheet(email);
return ContentService.createTextOutput("Added to sheet!");
}
function testGet() {
var queryString = "[email protected]";
var url = ScriptApp.getService().getUrl() + queryString;
var result = UrlFetchApp.fetch(url, {
"method": "GET",
"followRedirects": true,
"muteHttpExceptions": true
});
if (result.getResponseCode() == 200) {
console.log(result.getContentText());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment