Guest User

Untitled

a guest
Jan 16th, 2018
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. function onEdit(e) {
  2. var ss = SpreadsheetApp.getActiveSpreadsheet();
  3. var sheet = ss.getSheetByName('Lab Analysis');
  4.  
  5. // define edit range
  6. var editRange = sheet.getActiveRange();
  7. var editRow = editRange.getRow();
  8. var editCol = editRange.getColumn();
  9. var range = sheet.getRange("AG6:AG");
  10. var rangeRowStart = range.getRow();
  11. var rangeRowEnd = rangeRowStart + range.getHeight();
  12. var rangeColStart = range.getColumn();
  13. var rangeColEnd = rangeColStart + range.getWidth();
  14.  
  15. // if cells lie within the edit range, run the following script
  16. if (editRow >= rangeRowStart && editRow <= rangeRowEnd
  17. && editCol >= rangeColStart && editCol <= rangeColEnd) {
  18.  
  19. // set today's date and store a date object for today
  20. var date = ss.getSheetByName('Daily Process
  21. Limits').getRange("B1").setValue(new Date()).getValue();
  22.  
  23. // get values in date range
  24. var daterange = sheet.getRange("A6:A").getValues();
  25.  
  26. // iterate the values in the range object
  27. for(var i=0; i<daterange.length; i++) {
  28.  
  29. // compare only month/day/year in the date objects
  30. if (new Date(daterange[i]).setHours(0,0,0,0) ==
  31. date.setHours(0,0,0,0)) {
  32.  
  33. // if there's a match, set the row
  34. // i is 0 indexed, add 6 to get correct row
  35. var today_row = (i+6);
  36. var today_set = ss.getSheetByName('Daily Process
  37. Limits').getRange("D1").setValue(today_row);
  38. var today_fos_tac_f1 = sheet.getRange("AE"+today_row).getValue();
  39. var today_fos_tac_f2 = sheet.getRange("AF"+today_row).getValue();
  40. var today_fos_tac_pf = sheet.getRange("AG"+today_row).getValue();
  41.  
  42. // pop up notifications to operator
  43. if (today_fos_tac_f1 > 0.3) {
  44. SpreadsheetApp.getUi().alert('pop up notification content'); }
  45. if (today_fos_tac_f2 > 0.3) {
  46. SpreadsheetApp.getUi().alert('pop up notification content'); }
  47. if (today_fos_tac_pf > 0.3) {
  48. SpreadsheetApp.getUi().alert('pop up notification content'); }
  49.  
  50. // Set email addresses
  51. var emails = ['emailaddress@gmail.com'];
  52.  
  53. // send email notification to site manager
  54. if (today_fos_tac_f1 > 0.3) {
  55. MailApp.sendEmail(emails, 'High FOS:TAC in Fermenter 1', 'email content');}
  56. if (today_fos_tac_f2 > 0.3){
  57. MailApp.sendEmail(emails, 'High FOS:TAC in Fermenter 2', 'email content');}
  58. if (today_fos_tac_pf > 0.3){
  59. MailApp.sendEmail(emails, 'High FOS:TAC in Post Fermenter', 'email content');}
  60. }
  61. }
  62. }}
Add Comment
Please, Sign In to add comment