Home > Net >  How to write a Google Script that send an email notification once a specific column has been edited?
How to write a Google Script that send an email notification once a specific column has been edited?

Time:07-22

I am currently trying to write a google script that will send me an email every time a specific column has been edited on google sheet.

The spreadsheet is titled "Sales" and the tab is "RO". Columns D to H will be edited with info on an irregular basis which is why I want to try set up an email notification to alert me when an edit has been made.

An error message saying

Exception: The parameters (String) don't match the method signature for SpreadsheetApp.getActiveSpreadsheet.

appears when I try run the code

Here is the code:

function sendMailEdit(e){
var ss = SpreadsheetApp.getActiveSpreadsheet("Sales").getSheetByName("RO");
if (be.range.columnStart != 3 || e.value != "Rollover") return;
const rData = e.source.getActiveSheet().getRange(e.range.rowStart,4,1,5).getValue();
let n = rData[0][4];
let d = new Date(rData[0][3]).toLocaleDateString("en-US");
let amo = rData[0][7];

let msg = "Account ID "   n   " ("   d   ") Request Date "   "Transfer Amount "   amo;
Logger.log(msg);
GmailApp.sendEmail("[email protected]", "New Sale", msg)
}

CodePudding user response:

You do not have to mention Sales if your script in bound to the spreadsheet

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("RO")

By the way, what is be ?

Moreover, if you want to send an email, you will have to trigger your function,.

CodePudding user response:

To fix the error message, remove

var ss = SpreadsheetApp.getActiveSpreadsheet("Sales").getSheetByName("RO");

as ss is not used.

Also replace

be.range.columnStart

by (remove b)

e.range.columnStart

and replace

const rData = e.source.getActiveSheet().getRange(e.range.rowStart,4,1,5).getValue();

by (add an s / use getValues() instead of getValue())

const rData = e.source.getActiveSheet().getRange(e.range.rowStart,4,1,5).getValues();

as it looks that these lines have typos.

  • Related