I am new to google scripts and event handling and I do not clarify with the API.
I'm looking to create a script that monitors certain cells in a specific sheet of a google sheet book. These cells contain a formula that depends on the content of a range of other cells that the user modifies manually. Thus, when the user edits the latter, the former change.
The idea is that if the value of any of the cells (C61: C66) changes above a pre-set threshold (0.25) ( the user does NOT modify them directly ) an e-mail is sent. Pej: cell C61 contains the formula:
=CONTAR.SI(D61:61, "No")/E$67
What is intended is that if after changing manually any cell of D61: 61 the value of C61 is greater than 0.25, the system sends a pair of e- mails The same would happen with cells C62: C66
For now what I have is:
function sheetTracker() {
// Version 2.0
var ss = SpreadsheetApp.getActiveSpreadsheet(); // Obtenemos a quehoja del libro pertenece la celda que ha cambiado
var cell = SpreadsheetApp.getActiveRange(); // Obtenemos la celda que ha cambiado
var celda = cell.getA1Notation(); // Obtenemos el nombre de la celda que ha cambiado
var currentSheet = ss.getActiveSheet();
var hoja = currentSheet.getName(); // Obtenemos el nombre de la hoja en la que ha cambiado la celda
var editRange = {top : 61,bottom : 66, column : 3}; // Celdas a verificar: C61:C66
// Si no se ha modificado una celda de la hoja de asistencia que toca salimos
if (hoja != "Mi hoja") return;
// Si las celdas modificadas estan fuera de rango salimos
var thisRow = e.range.getRow();
if (Number(thisRow) < editRange.top || Number(thisRow) > editRange.bottom) return;
var thisCol = e.range.getColumn();
if (Number(thisCol) != editRange.column) return;
var range = e.range; // La celda que se ha cambiado
var columna = range.getColumn(); // La columna en la que esta la celda que ha cambiado
var fila = range.getRow(); // La fila en la que esta la celda que ha cambiado
var valor = Number(range.getValue()); // El nuevo valor de la celda
var valor = Number(ss.getActiveCell().getValue());
var alumno = range.offset(0,2);
var email = range.offset(0,-2);
var yes = range.offset(0,1);
var justified = range.offset(0,-1);
if ( celda == 'C61' && valor > 0.25) {
MailApp.sendEmail(email, subjecta, messagea);
MailApp.sendEmail(director, subjectd, messaged);
}
My questions are:
1) - Is it possible to define a list of cells to check such that ['C61', 'C62', 'C63', 'C64', 'C65', 'C66']
and do something like in python "cell in ['C61', 'C62', 'C63', 'C64', 'C65', 'C66']
2) -The "e.range" comes from trying to use an onEdit (e) function where "e" is an event. However, I am trying not to use an event. The use of triggers is not clear to me. It seems that there are "reserved" functions that are "auto-triggered" like "onEdit (e)" and "onChange (e)" when editing or changing a cell and others that do not, needing "external" triggers. What options do I have? ?