• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript New value in google email script


New Coder
function sendemail(){

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheetname = "Sheet1"
var sheet = ss.getSheetByName(sheetname);
// parameters to get a data range
var datafirstrow = 2;
var dataColU = 4; // Column D = 4
var dataColTarget = 8; // Column Z = 26
// get the last row
var LR = sheet.getLastRow();
// Logger.log("DEBUG: the last row = "+LR)
if (LR <= datafirstrow){
// Logger.log("DEBUG: no data")
// get range for column U
var sourcerange = sheet.getRange(datafirstrow, dataColU, LR-datafirstrow+1)
// Logger.log("DEBUG: the range = "+sourcerange.getA1Notation())
var sourcevalues = sourcerange.getValues();
// get the target range (assume column V)
var targetrange = sheet.getRange(datafirstrow, dataColTarget, LR-datafirstrow+1)
// Logger.log("DEBUG: the target range = "+targetrange.getA1Notation())
var targetvalues = targetrange.getValues();

// calculate the number of rows of data
var numrows = LR-datafirstrow+1;
// Logger.log("DEBUG: the number of rows = "+numrows)
for (var i=0;i<numrows;i++){
if (sourcevalues[i][0] != targetvalues[i][0]){
// values do not match, so Column U has changed
// so send email
var rownumber = i+datafirstrow;

GmailApp.sendEmail("[email protected]","Subject", "New Name Added - See Cell U" + rownumber + " Sheet Name")

//Logger.log("DEBUG: i="+i+", send an email for row number "+rownumber);
// update the revised source data to target range

How can I add a cell value in addition to the rownumber in the email body? For example: if a cell contains the number 6, I would like to see the value 6 in the body of the email
I would also like the email body to include the values from adjacent cells in a given row. Can anyone help me how to do this?
Top Bottom