Editor’s Note: Guest Author Md. Ahsanur Rashid is a MS student in the department of Computer Science at North Carolina State University. He recently participated in Google Apps Script Hackathon.
Step 1 - Every weekend, each friend on the list will be sent an email with a link where he/she can choose the desired time before a preset cutoff. To make the form more user friendly, we designed the form to allow users to choose from a list box rather than directly entering a value.
function sendReminder() {
// get the sheet and last row data
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = sheet.getLastRow();
for ( var i = 2; i <= lastRow; i++) {
// get the email and name for each row of the form
var userEmail = sheet.getRange(i, getColIndexByName("Email")).getValue();
var userName = sheet.getRange(i, getColIndexByName("Name")).getValue();
// send an email to the user
MailApp.sendEmail(userEmail, "Please send us your best time!",
"Hi" + userName +",\n\n" + "Please fill the form at ....",
{name : "Best Time Chooser"});
}
}
Step 2 - At the cutoff time, our script will process all the responses from all the friends. We configured an Apps Script trigger which will execute the getBestTime() function at the cutoff time on Sunday. The script reads the selected time preferences from the spreadsheet using Spreadsheet Service in Apps Script. The most popular response wins. In case of a tie, a default time (Sunday) is chosen.
Step 3 - After calculating the most popular time preference, the script uses Mail Services to send an email to each friend. All the friends are sent an email to let them know the chosen date.
A very useful feature in Apps Script is debugging. And it could not have been easier to debug in Google Apps Script. We can use Logger.log(); to log the values and debug based on those. Using View->Logs inside the script editor we can see the log file.
To summarize, it was an interesting experience using Apps Script at Google Apps Script Hackathon. Google Apps Script is quite intuitive and great for automating manual tasks.
Posted by Md. Ahsanur Rashid
No comments:
Post a Comment