0

I am trying to complete the script to send an email for any edit of a specific tab on a google sheet, but i keeps giving me this error:

TypeError: Cannot read properties of undefined (reading 'range')

My script is:

function sendEditNotification(e){

 if (e.range.columnStart != 6 || e.value != "Checked in") return;

 const rData = e.source.getActiveSheet().getSheetByName("Daily PSP List").getRange().getValues();

 let Names = rData[1][3];

 let Email = "Chris.DonovanBayley@swale.at";

 let Year = rData[1][3];

 let Duration = rData[3][3];

  let msg = "Hi, " + Names + " has been marked " + CurrentStatus

 MailApp.sendEmail(email, "PSP attendance", msg)

sheet format. enter image description here

Is anyone able to educate me as to what I have got wrong please and help? Thank you in advance.

Help to correct the script.

George
  • 1,196
  • 1
  • 2
  • 10
  • I think that from your showing script, the reason for your current issue of `TypeError: Cannot read properties of undefined (reading 'range')` might be due to that you might have directly run the script although there is no event object. How about this? – Tanaike Feb 28 '23 at 00:28
  • Further to @Tanaike 's comment. Have you created an installable `onEdit` trigger for `sendEditNotification(e)`? If not, then you must do that; then the script will run when you edit the spreadsheet. – Tedinoz Feb 28 '23 at 05:29
  • Hi,I have created an on edit trigger and tried to try the script whilst making the edit to see if it worked, rather than just running in a sandbox. – Rugby2014 Feb 28 '23 at 09:59

0 Answers0