From 096aca28d6aa7ae5f4083fd6685cc3a31854f902 Mon Sep 17 00:00:00 2001 From: Miguel Sozinho Ramalho <19508417+msramalho@users.noreply.github.com> Date: Wed, 11 Jan 2023 12:30:41 +0000 Subject: [PATCH] Create Monitor.gs --- monitaor-sheet-for-values/Monitor.gs | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 monitaor-sheet-for-values/Monitor.gs diff --git a/monitaor-sheet-for-values/Monitor.gs b/monitaor-sheet-for-values/Monitor.gs new file mode 100644 index 0000000..ee41629 --- /dev/null +++ b/monitaor-sheet-for-values/Monitor.gs @@ -0,0 +1,34 @@ + +const ERROR_MESSAGE = "NOT_FOUND" +const SHEET_TO_MONITOR = "your-sheet-name" +const ALERT = "Custom alert message for this error" + +function main() { + console.time("full"); + { + let sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(SHEET_TO_MONITOR); + assert(!findInSheet(sheet, ERROR_MESSAGE), ALERT) + } + console.timeEnd("full"); +} + +function findInSheet(sheet, SEARCH_FOR) { + let rows = sheet.getDataRange().getValues(); + for (const row of rows) { + for (const cell of row) { + if (cell == SEARCH_FOR) { + console.log(`"${SEARCH_FOR}" FOUND in "${sheet.getSheetName()}"`) + return true; + } + } + } + console.log(`"${SEARCH_FOR}" NOT FOUND in "${sheet.getSheetName()}"`) + return false; +} + +function assert(condition, message) { + if (!condition) { + console.error(message); + throw message; + } +}