Trigger an email when a cell has certain values

2019-07-16 05:07发布

I am a basketball coach & I am creating a dashboard to monitor my players' social media. I'm using IFTTT.com to pull in all of my players' tweets in real-time to a spreadsheet. I'm trying to write a code that if one of my players uses an inappropriate word, it'll trigger an email to me of that cell. I feel like I'm on the right track, but some guidance on my code is greatly appreciated.

function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet()

var cell = ss.getActiveCell().activate();

Logger.log( cell.getA1Notation() );

if (cell.getValue().match("ass")) {
MailApp.sendEmail("example@example.com", "Notice of possible inappropriate tweet", cell;}

}`

This is the code for just one inappropriate word, obviously, as I'm just trying to get the basics of the coding down before I add 100 inappropriate words. The trouble is that if the sheet pulls in three tweets at the same time, it's only going to check on the last one, so that's where my main troubles lie right now.

Any guidance or help here is greatly appreciated!

1条回答
趁早两清
2楼-- · 2019-07-16 05:51

I agree with Camerons comments above, if you can describe what's not working for you specifically, that would give us an idea of what you need help with.

As it stands, your code runs for me, and it will email me when I edit a cell to contain the word 'ass'.

However, one catch is that currently in the body of the email you have the variable 'cell' which will only return the word 'range'.

Here's a slightly updated version that provides more helpful notation in the email:

function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();//Get the spreadsheet
var sheet = ss.getActiveSheet()//Get the active sheet
var cell = ss.getActiveCell().activate();//Get the active cell. 
var badCell = cell.getA1Notation();//Get the cells A1 notation.
var badCellContent = cell.getValue();//Get the value of that cell. 

  if (badCellContent.match("ass")){
    MailApp.sendEmail("example@example.com", "Notice of possible inappropriate tweet", "The cell: " + badCell + " contains the word: " + badCellContent + ".");
  }
}
查看更多
登录 后发表回答