Trigger email when a cell has specific values

I am a basketball coach and I am creating a dashboard to monitor my players' social networks. I use IFTTT.com to download my players ’tweets in real time to a spreadsheet. I am trying to write a code that, if one of my players uses the wrong word, it will call me an email of this cell. I feel like I'm on the right track, but some recommendations on my code are 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 one non-local word, obviously, since I'm just trying to get the basics of coding before adding 100 non-local words. The trouble is that if a sheet pulls three tweets at a time, it will only check the last one, so where my main problems lie right now.

Any advice or help here is greatly appreciated!

+2
source share
1 answer

I agree with the comments of Camerons above, if you can describe what specifically does not work for you, this will give us an idea of ​​what you need help with.

In its current form, your code runs for me, and it will send me an email when I edit the cell to contain the word "ass".

However, one catch is that currently there is a variable 'cell' in the body of the message, which will only return the word 'range'.

Here's a slightly updated version that provides more useful 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 + "."); } } 
0
source

Source: https://habr.com/ru/post/1205464/


All Articles