Comrade Nikolai
Comrade Nikolai

Reputation: 23

How to add a function to an HTML button in Gmail

I recently made a Google Apps Script that runs onSubmit of a Google form. It automatically emails the info captured in the form to the approving manager in an html format.

I've attempted to add additional workflow by including two buttons in the email - "Approve" and "Deny". However, I am unable to attach a function to these buttons (e.g., the submit button would forward the email to X, etc).

I would appreciate if anyone could help me out with this - I haven't been able to find/understand online solutions, and I fear I may be over my head in this. Below is my code:

     function notfiy(e) {


  var username = e.values[1].toString();
  var requestfor =  e.values[2].toString();
  var location =e.values[3].toString();
  var department = e.values[4].toString();
  var phonenumb = e.values[5].toString();
  var extension = e.values[6].toString();
  var approver = e.values[7].toString();
  var computer = e.values[8].toString();
  var monitor = e.values[10].toString();
  var accessories = e.values[12].toString();

  var html = 
    '<body>' +
    +'<h2>'+ username + ' has submitted a request to purchase equipment for ' + requestfor + ' </h2>' + '<br>' + '<br>' +
    'Location: ' + location +
    '<br> Department: ' + department +
    '<br> Phone Number: ' + phonenumb +
    '<br> Extension: ' + extension +
    '<br> <br> The following materials have been requested for purchase: ' +
    '<br> <br> Software: ' +
    '<br> Computer: ' + computer +
    '<br> Monitor: ' + monitor +
    '<br> Computer Accessories: ' + accessories + '<br> <br> The ship to location for said materials is :' + '<br> <br> <br> <br>' +

    '<input type="submit" value="Approve" />' + '<br>'+
    '<input type="submit"  value="Deny" />' +
    '</body>'; 

    MailApp.sendEmail(approver, "Equipment Request: " + username, 'No html body);', {htmlBody: html});


}

Upvotes: 2

Views: 3639

Answers (2)

James Ferreira
James Ferreira

Reputation: 346

I've added a video tutorial about how to get this done: https://sites.google.com/site/scriptsexamples/home/announcements/emailapprovalusinggooglescriptandaform

Upvotes: 1

James Ferreira
James Ferreira

Reputation: 346

You simply use a form in the html body however, I have had some odd behavior where you do one approval and that works fine but on the next one Gmail thinks you already sent it and wont open the dialog again.

What I have been doing is to use standard links (anchors) that can be made to look like buttons. these will take you to a published UiApp page where the choice is added to the end of the url. approve=true.

This is passed in e.parameter so:

doGet(e){
 var approve = e.parameter.approve;
 //do something with the info. 
} 

You can see some of this behavior in this tutorial: http://googlescriptexamples.com/tickets and the Workflow chapter in the Google Script Book works like this.

Upvotes: 0

Related Questions