Search code examples
javajavascriptgoogle-apps-scriptscriptinggoogle-apps

Execution Success, but no Results?


So, i'm working on creating this approval workflow for google forms. I'm new to this, I've searched online and read through some tutorials as well as google's but most of the stuff that I have seen has been deprecated. I think i have my triggers current, they're set to onformsubmit and when i check the execuion log, it says success. But, still I have not received any e-mails. Can anyone lead me in the right direction?

Thank You!

  function sendEmail(e){
  var requestorEmail = e.values[1];
  var SupervisorsEmail = e.values[2]; //manager e-mail
  var ApplicationID = e.values[3];
  var ApplicationDate = e.values[4]; //dateconfirmationSent
  var ApplicantName = e.values[5]; //interpreter name
  var MBO = e.values[6];
  var Processor = e.values[7];
  var ShortReason = e.values[8];
  var ReasonCode = e.values[9];
  var approval = e.values[10];  //the one we need to modify
  var url ='https://script.google.com/a/macros/bbva.com/s/AKfycbwKtqBa7L_oB2qnkQclVmKuWLnxj6ic74CAalUmxEDCv0SkjCY/exec';


  /**might be that the & needs to be a ?*/
  var approve = url + '?approval=true'+'?reply='+requestorEmail;
  var reject = url + '?approval=false'+'?reply='+requestorEmail;

  var html = "<HTML><body>"+
           "<h2>please review</h2><br />"
  +"<P>" + ApplicationID +"  " + ApplicationDate
  +"<p>" + "MBO:"+ MBO  
  +"<p>" + "Processor:" + Processor
  +"<p>" + "Short Reason: "+ ShortReason
  +"<p>" + "requester: "+ requestorEmail+
  +"<p>" + "Reason Code: "+ ReasonCode+ "  "+
   "<p>"+

   "<a href="+ approve +">Approve</a><br />"+
   "<p>"+

   "<a href=" +reject+">Reject</a><br />"+
          "</HTML></body>";

  MailApp.sendEmail(SupervisorsEmail, "Approval Request", "what no html?", {htmlBody: html});

  }

function doGet(e) {

 var app = UiApp.createApplication();

 var aprovalResponce = (e.parameter.approval == 'true') ? 'Approved.' : 'Sorry, you need to reschedule';

  var msg = "Your manager said :" + aprovalResponce;

  var replyEmail = e.parameter.reply;
 Logger.log(replyEmail);

  MailApp.sendEmail(replyEmail, "Approval Request", msg);

  var helloWorldLabel = app.createLabel(msg);
  app.add(helloWorldLabel);


  return app;
}

This is my execution transcript

 [15-05-28 11:24:54:243 CDT] SpreadsheetApp.getActiveRange() [0 seconds]
 [15-05-28 11:24:54:243 CDT] Range.getRow() [0 seconds]
 [15-05-28 11:24:54:243 CDT] Range.getLastRow() [0 seconds]
 [15-05-28 11:24:54:243 CDT] Range.getColumn() [0 seconds]
 [15-05-28 11:24:54:244 CDT] Range.getLastColumn() [0 seconds]
 [15-05-28 11:24:54:244 CDT] SpreadsheetApp.getActiveSpreadsheet() [0 seconds]
 [15-05-28 11:24:54:283 CDT] Starting execution
 [15-05-28 11:24:54:713 CDT] MailApp.sendEmail(i removed personal info) [0.425 seconds]
 [15-05-28 11:24:54:714 CDT] Execution succeeded [0.426 seconds total runtime]

The E-Mails are currently working, but now I run into this error once I click "Approve" in my e-mails. Any idea?

[15-05-28 16:19:46:941 CDT] Starting execution
[15-05-28 16:19:46:965 CDT] UiApp.createApplication() [0.001 seconds]
[15-05-28 16:19:46:967 CDT] Logger.log([undefined, []]) [0 seconds]
[15-05-28 16:19:46:968 CDT] MailApp.sendEmail([undefined,    Approval Request, Your manager said :Sorry, you need to reschedule]) [0 seconds]
[15-05-28 16:19:46:992 CDT] Execution failed: Invalid email: undefined (line 52, file "Code", project "Send emails") [0.006 seconds total runtime]

Solution

  • Even though you are definitely getting the email that you need from the form, try 'Hard Coding' and email, and see if the MailApp.sendEmail() function works:

    MailApp.sendEmail('email@gmail.com", "Approval Request", "what no html?", {htmlBody: html});
    

    After this line of code:

    var SupervisorsEmail = e.values[2]; //manager e-mail
    

    Enter a Logger.log() statement:

    var SupervisorsEmail = e.values[2]; //manager e-mail
    Logger.log('SupervisorsEmail: ' + SupervisorsEmail);
    

    Then submit the form, and look under the VIEW menu and the LOGS. Are you getting the email?

    Also, look in the 'Sent' folder, to see if there was an email sent, but never received.