-3

Im trying to implement the solution proposed by user79865 in this thread (which is closed and hence I opened this new question):

[https://webapps.stackexchange.com/questions/87346/add-a-script-trigger-to-google-sheet-that-will-work-in-android-mobile-app][1]

function onEdit(e) {
  if (e.range.getW1Notation() == 'X1') {
    if (/^\w+$/.test(e.value)) {        
      eval(e.value)();
      e.range.clear();
    }
  }
}

Unfortunately I get this error:

TypeError: Cannot read property "range" from undefined. (Row 4, File "Makros")

Row 4 is:

  if (e.range.getW1Notation() == 'X1') {

As Im a newbie I have no clue what is going on.

Thanx.

mortpiedra
  • 81
  • 8
  • The referred Web Applications question is protected, not closed. – Rubén Dec 01 '19 at 17:55
  • Does this answer your question? [How can I test a trigger function in GAS?](https://stackoverflow.com/questions/16089041/how-can-i-test-a-trigger-function-in-gas) – Rubén Dec 01 '19 at 17:56

1 Answers1

1
function onEdit(e) {
  if (e.range.getA1Notation() == 'X1') {
    if (/^\w+$/.test(e.value)) {        
      e.range.clear();
    }
  }
}

Note: You can't run this function without supplying it an event object.

Cooper
  • 59,616
  • 6
  • 23
  • 54
  • Ugh! En event object??? The original post didnt mention anything to that sort. Gotta figure out what that is... but Cooper am I asking something stupid when I ask: why did you leave out the statement: `eval(e.value)();` from your function above??? – mortpiedra Nov 30 '19 at 23:19
  • The event object is supplied by the simple trigger when a sheet is edited. But none is supplied by you run from Script Editor. – Cooper Nov 30 '19 at 23:45
  • where does the e in e.value come from? – Cooper Mar 27 '21 at 14:23