Answer the question
In order to leave comments, you need to log in
How to fire onEdit from editor or programmatically?
Am I correct in understanding that the code below will fire a trigger on a specific cell change, and not any one? When run, it gives the error "TypeError: Cannot read property 'range' of undefined (line 3, file se)".
Here is the code:
function onEdit(e) {
// Get cell edited. If it B6, then do something
var cellAddress = e.range.getA1Notation();
if (cellAddress === 'B26') {
//To Do. Code here if cell edited was B26
Logger.log('the check worked!');
};
}
Answer the question
In order to leave comments, you need to log in
As far as I understand, you are trying to call a function onEdit
from another function or from the editor.
Error Parsing
Error
TypeError: Cannot read property 'range' of undefined (line 3, file se)
se
in 3й строке
there is some variable with value undefined
, whose property range
cannot be read. Everything is obvious here - it undefined
has no properties. e
. And we get it into a system function onEdit
. This means that the system itself passes the context to this function. /**
* Тестирование триггера для события EDIT
*/
function runOnEdit() {
var source = SpreadsheetApp.getActive();
var range = source.getRangeByName('Sheet!!B26');
/**
* @type {GoogleAppsScript.Events.SheetsOnEdit}
*/
var e = {
authMode: ScriptApp.AuthMode.LIMITED,
oldValue: undefined, // ну или что хотите
range: range,
value: range.getValue(),
source: source,
triggerUid: 0,
user: Session.getActiveUser(),
};
onEdit(e);
}
/**
*
* @param {GoogleAppsScript.Events.SheetsOnEdit} e
*/
function onEdit(e) {
// Работает простой триггер
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question