Skip to content

Instantly share code, notes, and snippets.

@saamerm
Created January 10, 2023 14:23
Show Gist options
  • Save saamerm/d03d2e656633a6d48bb1ace8c16e3565 to your computer and use it in GitHub Desktop.
Save saamerm/d03d2e656633a6d48bb1ace8c16e3565 to your computer and use it in GitHub Desktop.
Email Collection App Script javascript code
function doPost(request){
var resultObject = JSON.parse(request.postData.contents);
var result = processResult(resultObject);
return ContentService
.createTextOutput(JSON.stringify(result))
.setMimeType(ContentService.MimeType.JSON);
}
function processResult(resultObject)
{
// Open Google Sheet using ID
var sheet = SpreadsheetApp.openById("{YOUR SHEET ID}"); // Insert your sheet Id from the url
var result = {"Status": "SUCCESS", "Message": "Thank you for your feedback"};
try{
// Get all Parameters
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date+' '+time;
// Append data on Google Sheet
var rowData = sheet.appendRow([resultObject.Email, dateTime]);
}catch(exc){
var rowData = sheet.appendRow(["Email", "0"]);
// If error occurs, throw exception
result = {"Status": "FAILED", "Message": exc};
}
// Return result
return result;
}
function test(){
var Email = "[email protected]"
var myJSObject='{"Email": "' + Email + '"}';
var result = processResult(JSON.parse(myJSObject))
console.log(result)
}
// https://script.google.com/macros/s/{YOUR SCRIPT UNIQUE ID}/exec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment