2
votes

I have a call to a toast message within an installable onEdit trigger function that displays a message in the Google Sheets interface whenever an edit is made. The message shows up as expected for users that are logged in to their Google account, but it doesn't show up in the interface when the editor is anonymous.

I have a Sheets file that has anonymous editing enabled ("Anyone with the link"). There is a standalone Google Apps Script project that has installed an installable onEdit trigger. Everything in the function executes successfully for both anonymous and logged in users except for the toast message, which only shows up for logged in users.

The installable onEdit trigger is set up to execute the showMessage function.

Trigger Installed With:

ScriptApp.newTrigger('showMessage').forSpreadsheet('thefileid').onEdit().create();

showMessage Function:

function showMessage(e) {

    var msg = 'Some msg';
    var title = 'Some title';
    var file = e.source;
    var activeSheet = file.getActiveSheet();
    file.toast(msg, title);

    // do other things

}

The toast message appears for logged in users, not anonymous ones. The 'other things' in the function work as expected for everyone. I'm looking for a way to show anonymous users that message (or looking for some way to communicate automated messages to them). The script project is standalone and not container-bound, so I can't use the Ui class to notify them. Container bound scripts are not an option, as this script is substantial in size and gets run on multiple files.

2
See the required scopes in the documentation--have you checked if your anonymous users have this authorization enabled? There's the reference for triggers here if you haven't already checked that; something else you might try is disabling this trigger and checking that the behavior stops as expected, so as to avoid confusion if your script is actually being triggered by something else (and this doesn't work for anyone).sinaraheneba

2 Answers

5
votes
  • You want to display a message when the cells of Spreadsheet are edited by anonymous.
  • The Spreadsheet is publicly shared for anonymous users as the editor.

If my understanding is correct, how about this answer? Unfortunately, even when the installed OnEdit event trigger is used, when anonymous users are edited, toast() and Class Ui cannot be used. So as one of several workaround, I would like to propose to use the images. Fortunately, insertImage() can be used for this situation. So I'm using this workaround. Please think of this as just one of several answers.

Before you use this script, please prepare an image for displaying.

Sample script:

Before you use this script, please set the file ID of the image. And please install the OnEdit event trigger for the function of showMessage().

function showMessage(e) {
  var fileId = "###"; // Please set the file ID of the image.

  var sheet = e.source.getActiveSheet();
  var blob = DriveApp.getFileById(fileId).getBlob();
  var image = sheet.insertImage(blob, 2, 3);
  Utilities.sleep(3000);
  image.remove();
}
  • In this sample script, when the cell is edited, the prepared image is displayed and waited for 3 seconds, and then, the image is removed.

Result:

enter image description here

Note:

  • Of course, you can create an image for displaying with the script. But in this case, the process cost will become high. As the result, the time until the image is displayed becomes long. So I proposed to use the image which was created in advance.

References:

If I misunderstood your question and this was not the direction you want, I apologize.

0
votes

As you can see in the documentation:

Apps Script requires user authoritaztion to access private data from built-in Google Services or advanced Google services

That means you can share your script with anyone, but they need to log in to use the script.