vejvik

script google sheet

Jul 22nd, 2023
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. function sendEmailIfValueLessThan30() {
  2. // Declare variables
  3. var cells = SpreadsheetApp.getActive().getRange("D4:D6");
  4. var values = cells.getValues();
  5. var recipients = ["[email protected]", "[email protected]"];
  6. var subject = "končí";
  7. var body = "";
  8.  
  9. // Loop through the cells and check if the value is less than 30
  10. for (var i = 0; i < values.length; i++) {
  11. if (values[i] == 30) {
  12. var name = SpreadsheetApp.getActive().getRange("B" + (i + 4)).getValue();
  13. body += "někomu " + name + " má " + values[i] + " konec.\n";
  14. }
  15. }
  16.  
  17. // If there are any values less than 30, send an email
  18. if (body.length > 0) {
  19. for (var recipient of recipients) {
  20. MailApp.sendEmail(recipient, subject, body);
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment