Skip to content

Instantly share code, notes, and snippets.

View sauntimo's full-sized avatar

Tim Saunders sauntimo

View GitHub Profile
@sauntimo
sauntimo / SetUpObject.js
Created November 9, 2012 12:51
Creating a usable object from a form submission
function formSubmitReply(e) {
/* ----- CREATE NEW OBJECT FROM SUBMISSION ----- */
var NewSubmission = {
"Timestamp" : e.values[0],
"Favourite Colour" : e.values[1],
"Explanation" : e.values[2],
}
@sauntimo
sauntimo / Default.js
Created November 9, 2012 16:05
Default spreadsheet code
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
@sauntimo
sauntimo / TestEmail.js
Created November 9, 2012 17:38
Trigger Test Email
function OnSubmit(e){
MailApp.sendEmail("gassnippets@gmail.com", "Your form was submitted!",
"Hey you!" +
"\n\n Someone submitted your form. Here's what they had to say:" +
"\n\n Favourite Colour: " + e.values[1] +
"\n Explanation: " + e.values[2])
}
@sauntimo
sauntimo / ObjectPropertyLoop.js
Created November 9, 2012 19:51
Looping through Object Properties
function OnSubmit(e){
var NewSubmission = {};
var Properties = ["Timestamp","Favourite Colour","Explanation"];
var i = 0;
for(i = 0; i < Properties.length; i++){
NewSubmission[Properties[i]] = e.values[i];
}
@sauntimo
sauntimo / HTMLTable.htm
Created November 10, 2012 22:12
HTML table written out in full
<table style="border:2px solid black;width:500">
<tbody>
<tr><th colspan="2" bgcolor="#c7ced4">Section One: Product Details</th></tr>
<tr bgcolor="#d0eaf9"><td>Size</td><td>10" - £25</td></tr>
<tr><td>Style</td><td>Victoria Sponge Cake</td></tr>
<tr bgcolor="#d0eaf9"><td>Filling</td><td>Strawberry Jam</td></tr>
<tr><td>Topping</td><td>Buttercream</td></tr>
<tr bgcolor="#d0eaf9"><td>Decoration</td><td>Marshmallows, Strawberries, "Happy Birthday!"</td></tr>
<tr><th colspan="2" bgcolor="#c7ced4">Section Two: Delivery Details</th></tr>
<tr bgcolor="#d0eaf9"><td>First name</td><td>Joe</td></tr>
@sauntimo
sauntimo / BakeryConfirmationEmail.js
Created November 10, 2012 22:18
Snippet Bakery Order Confirmation Email
function CakeOrder(e){
/* ----- CREATE NEWSUBMISSION OBJECT ----- */
var NewSubmission = {};
@sauntimo
sauntimo / HTMLTable.js
Created November 10, 2012 23:44
Build HTML Response Table
/* ----- BUILD HTML RESPONSE TABLE ----- */
var HTMLtable = "<table style=\"border:2px solid black;width:500\" >";
var rowCount = 0;
for (var property in NewSubmission) {
if(NewSubmission[property].length != 0){
if(property.substring(0,7) === "Section"){
HTMLtable += "<tr><th colspan=\"2\" bgcolor=\"#c7ced4\">"+ property +"</th></tr>";
} else {
@sauntimo
sauntimo / CreateNewObject.js
Created November 10, 2012 23:52
Create NewSubmission Object
/* ----- CREATE NEWSUBMISSION OBJECT ----- */
var NewSubmission = {};
var Properties = ["Section One: Product Details","Size","Style","Filling","Topping","Decoration",
"Section Two: Delivery Details","First name","Family name","Email Address","Address","Delivery","Day","Month","Year"];
var i = 0;
var iSkip = 0;
@sauntimo
sauntimo / GASDateInputHandler.js
Created November 13, 2012 22:24
Google Apps Script Date Input handler
// Create string version of date entered to be read by humans
NewSubmission["Delivery Date"] = NewSubmission["Day"] + "-" + NewSubmission["Month"] + "-" + NewSubmission["Year"];
// create Javascript Date instance from date string
var OrderFor = new Date(NewSubmission["Month"] + " " + NewSubmission["Day"] + ", " + NewSubmission["Year"]);
// These properties aren't needed as we have NewSubmission["Delivery Date"] which is DD-MM-YYYY
delete NewSubmission["Day"];
delete NewSubmission["Month"];
@sauntimo
sauntimo / LogEmail.js
Created November 14, 2012 15:33
Log Email in GAS
function logIncomingEmails() {
var EmailLog = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Email Log")
var rows = EmailLog.getDataRange();
var numEmailRows = rows.getNumRows();
var Unlogged = GmailApp.getUserLabelByName("Unlogged")
var Logged = GmailApp.getUserLabelByName("Logged")
var UnloggedThreads = Unlogged.getThreads(0,50); // Returns an array of the first 50 unlogged threads. Hopefully there won't be more than 50 per minute!