When executed by someone else, the script execution does not resume after a call to Browser.msgBox()

| | August 5, 2015

I have a google spreadsheet where we mention some kind task our team has to do. Under one column we maintain the task status. I have added a Google app script which is triggered on change of spreadsheet. The main job of script is to send email notifications to some Google mailing groups about the change.
In the script I have used Browser.msgBox() to get input in yes/no. Now if I change the status in spreadsheet the popup comes and script resumes on button click with the value of button. If someone else make a change in spreadsheet, he gets the popup but on clicking the yes/no button script does not resumes.

My script looks something like this:

function statusChangeNotification(e) {
  var user = e.user;
  var sheet = e.source.getActiveSheet();
  var range = e.range;
  var val = e.value;

  if(sheet.getName() == RESPONSE_SHEET && isStatusField(range)){
    if(val == STATUS_YES){
      var sendMail = Browser.msgBox("Status Changed", "Do you wanna send a status notification mail?", Browser.Buttons.YES_NO);
      if(sendMail == "yes"){
        // code to send email using MailApp.sendEmail()
      }
    }
  }
}

On Google developer under class browser reference they have mentioned that

msgBox(title, prompt, buttons)

Pops up a dialog box with the given title, message and specified
buttons in the user’s browser. The msgBox method raises a client-side
message box with the given title, that displays the given message to
the user, and offers a choice of buttons to be displayed. Note that
this method causes the server-side script to be suspended. It will
resume automatically after the user clears the dialog, but JDBC
connections will not persist across the suspension.

What could be the problem that the script does not resume after a call to Browser.msgBox() for others? Please suggest some alternatives to achieve the same.

2 Responses to “When executed by someone else, the script execution does not resume after a call to Browser.msgBox()”

  1. What I understand is, you are using an onEdit trigger to send an Email after a popup confirmation. onEdit trigger is a simple trigger and it has limited scope.
    You can not send email with onEdit event. You will have to use Installable Triggers like time driven triggers etc.

    For better understanding of triggers and its scope, you may check these two reference links.

  2. samScholefield on November 30, -0001 @ 12:00 AM

    Please see the following thread:

    Quiet .hashCode() death of a script (GAS)

    Also, this logged GAS issue:

    https://code.google.com/p/google-apps-script-issues/issues/detail?id=2697

    tl/dr script will fail after Browser.msgBox() for all users other than script+spreadsheet owner

Leave a Reply