Brand new to code and need help!

40 views
Skip to first unread message

Sarah Mc

unread,
May 9, 2024, 8:57:56 AMMay 9
to Google Apps Script Community
I, like many before me, want to set up a checkbox system in a sheet to automatically send an email. I want each email to go to the same email address; its for a local NFP group seeking sponsorship.

This is roughly what I am using (clearly I have simplified and de-identified haha).

Every time I select a box in sheet "all potential sponsors" column e (invoice needed), I want an email to be sent to Rhys in sheet "key" row 4 (email address found C4).

I would like the email to say [Name] ie. fromA4 (or whatever the row is that the invoice checkbox was activated) "has offered to sponsor us and is requesting an invoice. Can you please reveiw and provide them with one."

This is what I have so far, please don't be too harsh with all my errors, this is honestly my first ever attempt at coding.
function triggerOnChange(event) { {
 
  var colChanged = event.range.getColumn(E);
  var rowChanged = event.range.getRow();
  var newValue = event.value;

  if (colChanged == 5 && newValue == "TRUE")
  {
    sendtheEmail(rowChanged)
  }
}

function sendtheEmail(_rowChanged) {
 // get data

  var sheet = SpreadsheetApp.getActiveSheet('All potential sponsors');
  var lastCol = sheet.getLastColumn();
  var rowData = sheet.getRange(_rowChanged,1,1,lastCol).getValues()[0];
  const emailAddr = SpreadsheetApp.getActiveSheet('key').getRange(C4)
  const eventRequested = rowData[]
 
 // create subject line
 const subjectLine = 'Sponsor requesting an invoice'

 // create email body
 const htmlBody = '<br>' +  'Hi HighLord,' + '<br>' + 'eventRequested' + 'has offered to sponsor us and is requesting an invoice. Can you please reveiw and provide them with one.' +'<br>'

 // send email
GmailApp.sendEmail(emailAddr,subjectLine,{htmlBody: htmlBody});
}

Reply all
Reply to author
Forward
0 new messages