Script to send email if a condition is reached.

130 views
Skip to first unread message

Gustavo

unread,
May 31, 2021, 11:43:47 PM5/31/21
to Google Apps Script Community
Hi guys, i am knew to google script and i would like a help from the community to write a code able to:

send an email with the graph "O26" to the addres "xxx...@gmail.com", if the cell B2 gets Y% higher than the cell B3

I alredy achieved to get the code running once each 2 hours, and it works for me.

Can you guys please help me? I would really appreciate, and learn a little more about the scripts sintax.

Brett Grear

unread,
Jun 1, 2021, 6:03:08 AM6/1/21
to Google Apps Script Community
Not exactly sure what you mean by graph 'O26'. Are you referring to a sparkline?
You also havn't mentioned whether the values in B2 and B3 are percentages already or not.  This makes a big difference because 15% is 5% higher than 10% but 15 is 40% higher than 10.  I am going to assume that the numbers are already percentages as this makes the if statement much simpler but it can easily be adapted to calculate either.
But sending an email through app script is relatively straight forward.

function sendEmail(recipient, b2, b3, y,o26) {
  var subject = 'Automated Email;
  var body = 'Whatever you want the email to say and include o26 (whatever that is)';
  if (b2-b3>y) {
    MailApp.sendEmail(recipient, subject, body);
  }
}

Reply all
Reply to author
Forward
0 new messages