Home > Software design >  Toast not showing up?
Toast not showing up?

Time:05-11

When I add toast to a function and run or debug that function the toast doesn't show, no errors in the log, and any logged messages before or after it do show in the console. However when I place the exact same toast code in a blank spreadsheet's apps script, the toast does show.

SpreadsheetApp.getActiveSpreadsheet().toast('Script is starting');
SpreadsheetApp.getActiveSpreadsheet().toast('⏰ Script running', 'Notice', 60); 

I do have both scopes from the documentation added in the Oauth scopes in the appsscript.json file:

https://www.googleapis.com/auth/spreadsheets.currentonly

https://www.googleapis.com/auth/spreadsheets

Are there other reasons why toast may not show in Sheets? Thank you!

CodePudding user response:

In order to make the Google Sheets UI methods like toast work properly,

  1. The script should be bounded to a spreadsheet or it should be an Editor add-on
  2. If the script will be run from the Google Apps Script Editor, it should be opened through the Google Sheets user interface:
    1. Open the spreadsheet
    2. Click Extensions > Apps Script

In order to make it easier to debug your code you might find more convenient to assign the active spreadsheet to a variable:

const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
if(spreadsheet) {
  spreadsheet.toast('Script is starting');
} else {
  throw new Error(`Can't get the active spreadsheet`);
}

Note: Sign-in into multiple accounts might cause scripts to not work properly. Try sign-out of all accounts, and sign-in only into the account having access to the spreadsheet or share the spreadsheet with your other accounts.

  • Related