The common pattern for checking the business logic before executing automation
Here’s a clever little snippet from Max Makhrov which combines Google Apps Script with conditional logic created using Google Sheets functions, the resulting cell value being used for the error message.
/** * @param {String} rangeName * * @returns {Boolean} toStopExecution */ function getStopMessageBoxFromNamedRange_(rangeName) { var ss = SpreadsheetApp.getActive(); var r = ss.getRangeByName(rangeName); var v = r.getValue(); if (v === '') { return false; } var stopHeader = 'The script was stopped'; Browser.msgBox(stopHeader, v, Browser.Buttons.OK); return true; }
If after reading Max’s post you are unsure how this works, here is an example Google Sheet with some test data and logic as well as a ‘My Menu’ open to test the bound script.
Source: Apps Script Pattern. Stop Script Execution on conditions from Sheet
Member of Google Developers Experts Program for Google Workspace (Google Apps Script) and interested in supporting Google Workspace Devs.