Logging the values of variables at a few points is essential when testing and debugging your code. The Logger
class is a helpful tool to do this and has a few methods that are essential to debug your code.
Update the showDialog
function as shown here:
function showDialog() { var ui = DocumentApp.getUi(); var response = ui.prompt( 'Greeting', 'Will you enter your name below?', ui.ButtonSet.YES_NO ); if (response.getSelectedButton() == ui.Button.YES) { Logger.log('Your name is %s.', response.getResponseText()); } else if (response.getSelectedButton() == ui.Button.NO) { Logger.log('You clicked \'NO\' button'); } else { Logger.log('You closed the dialog.'); } }
Run the showDialog
function as usual from the Add-ons menu. Do anything, for example, enter your name and click on Yes or No or close the dialog.
Now within the script editor, press Ctrl + Enter (Windows) or Command + Enter (Mac) or from the View menu, select Logs, then you can see the...