Home > OS >  Retrieve last row values for specific coloumns to send an email
Retrieve last row values for specific coloumns to send an email

Time:12-02

Google Sheet Data

I want to retreive CPC and Spend coloumn values of the last row and send that email on a daily basis. I have successfully retrieved CPC but I am unable to do it for spend coloumn.

Code.gs

function sendEmail () {

var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();
var data = ss.getRange(lr,3);
var values = data.getValues();
Logger.log(values);

var message = "Today CPC is "   values   "and spend is " ;
var email = "[email protected]";
var subject = "CPC Today"
MailApp.sendEmail(email,subject, message);

}

CodePudding user response:

In your script, the value is retrieved from only one column. I thought that this is the reason for your issue. So in this case, how about the following modification?

From:

var data = ss.getRange(lr,3);
var values = data.getValues();
Logger.log(values);

var message = "Today CPC is "   values   "and spend is " ;

To:

var [[cpc, , spend]] = ss.getRange(lr, 3, 1, 3).getValues();
var message = "Today CPC is "   cpc   " and spend is "   spend;

Reference:

  • Related