onEdit search function help

135 views
Skip to first unread message

Music Man

unread,
Jan 13, 2024, 12:35:31 PM1/13/24
to Google Apps Script Community
Hello!

I would GREATLY appreciate anyone's help, and happy to provide more information if needed.  I am new to this community AND new to writing scripts, so struggling to figure out the following:

I have created a google sheet that contains a form, an in order to automate said form I have been following a guide on YouTube to setup the background script.  One function that he put in his form was a search function, which I have copied word for word as I have the rest of his script which all worked.  Below is what I have written in the onEdit(e) script that he says to create:

function onEdit(e) {
  if(e.range.getA1Notation() !== "H3") return
  if(e.source.getSheetName() !== "Form") return
  search()  
}

H3 refers to the merged cells where you type your items you're searching for

and here is the error I receive:
1:55:23 PM
Error
TypeError: Cannot read properties of undefined (reading 'range')
onEdit.gs:2 Any ideas? ... MANY thanks in advance!

Keith Andersen

unread,
Jan 13, 2024, 12:47:04 PM1/13/24
to google-apps-sc...@googlegroups.com
Try:

function onEdit(e) {

let range = e.range;

let spreadSheet = e.source;

  if(e.range.getA1Notation() !== "H3") return

  if(e.spreadSheet.getSheetName() !== "Form") return

  search()  

}


Paying particular attention to exact spelling.


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/78ba70df-b701-48fe-907f-3a1e2d1f59afn%40googlegroups.com.

Emerson Maia

unread,
Jan 13, 2024, 12:50:27 PM1/13/24
to google-apps-sc...@googlegroups.com
O erro em seu código do Google Apps Script, o problema está relacionado ao objeto e que é passado para a função onEdit. Quando uma célula é editada, o Google Apps Script automaticamente passa um objeto de evento (e) para a função onEdit. Este objeto contém informações sobre a edição, incluindo o intervalo que foi editado (e.range) e a planilha onde ocorreu a edição (e.source).

O erro TypeError: Cannot read properties of undefined (reading 'range') indica que o objeto e não tem uma propriedade range. Isso geralmente acontece quando a função onEdit é executada manualmente no editor de scripts, pois nesse caso, nenhum objeto de evento é passado automaticamente.


--

Keith Andersen

unread,
Jan 13, 2024, 12:55:42 PM1/13/24
to google-apps-sc...@googlegroups.com
As our Spanish speaking friend pointed out - if you are calling this function from the editor it will give you that error also.

Do you get an error when you run it in the actual spreadsheet?  When you actually edit the cell in the spreadsheet, do you get any type of error?.

Music Man

unread,
Jan 13, 2024, 4:41:45 PM1/13/24
to Google Apps Script Community
Emerson & Keith ... I cannot THANK you enough ... your suggestions worked!  Thank you for taking the time to help me with this!

Blessings!

Keith Andersen

unread,
Jan 13, 2024, 5:08:06 PM1/13/24
to google-apps-sc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages