HOME‎ > ‎Announcements‎ > ‎

Email Approval using Google Script and a Form

posted May 6, 2012, 8:12 AM by James Ferreira   [ updated May 6, 2012, 8:25 AM by Romain Vialard ]
 Step by set instructions to get you going with email notifications for Google Drive forms.  

Chapter 8 in my book Google Script: Enterprise Application Essentials goes into the details of making a very sophisticated and dynamic workflow to handle any situation your manager may throw at you. 

YouTube Video


Example code

function sendEmail(e) {
  var email = e.values[1];
  var Item = e.values[2];
  var cost = e.values[3];  

  var url = '';
  
  var approve = url + '&approval=true'+'&reply='+email; 
  var reject = url + '&approval=false'+'&reply='+email;
  
  var html = "<body>"+
                "<h2>Please review</h2><br />"+
                Item +": " + cost+ "<br />"+ 
                "<a href="+ approve +">Approve</a><br />"+
                "<a href="+ reject +">Reject</a><br />"+
             "</body>";
  
  MailApp.sendEmail("<YOUR_EMAIL>", "Approval Request", 
                    "What no html?", {htmlBody: html});  
}



function doGet(e){
 
  var answer = (e.parameter.approval == 'true') ? 'Buy it!' : 'Not this time, Keep saving'; 
  
  MailApp.sendEmail(e.parameter.reply, "Purchase Request", 
                    "Your manager said: "+ answer);   
  
  var app = UiApp.createApplication();
  app.add(app.createHTML('<h2>An email was sent to '+ e.parameter.reply + ' saying: '+ answer + '</h2>'))
  return app
}


Comments