在stackoverflow社区的慷慨帮助下,我能够为我运行的池创建一个谷歌脚本,如果谷歌表单提交的池中存在异常读数,我会通知我,我的水生专家会填写进行。
我现在正在努力的是,我有三个游泳池,如果有人提交了游泳池A的表格,它会通知我。如果其他人提交了游泳池B的表格,如果游泳池A的读数仍然相同,它会通知我两者。
我有没有办法用google脚本编写:
如果池A的所有值都与前一个值相同, 不要再发送电子邮件
如果泳池B的所有值都与前一个值相同, 不要再发送电子邮件
如果所有Pool C的值与前一个相同, 不要再发送电子邮件
这是我的代码:
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
//----vvvvvPool
var IDPpHReading = sheet.getRange('A6:A7').getValue();
var IDPpHTest = sheet.getRange('B6:B7').getValue();
var IDPORP = sheet.getRange('A9:A10').getValue();
var IDPSetPoint = sheet.getRange('B9:B10').getValue();
var IDPCL = sheet.getRange('A12:A13').getValue();
var IDP_Filter1_INF = sheet.getRange('A16:A17').getValue();
var IDP_Filter1_EFF = sheet.getRange('B16:B17').getValue();
var IDP_Filter2_INF = sheet.getRange('A20:A21').getValue();
var IDP_Filter2_EFF = sheet.getRange('B20:B21').getValue();
//vvvvv----SPA
var SPApHReading = sheet.getRange('C6:C7').getValue();
var SPApHTest = sheet.getRange('D6:D7').getValue();
var SPAORP = sheet.getRange('C9:C10').getValue();
var SPASetPoint = sheet.getRange('D9:D10').getValue();
var SPA_Filter_INF = sheet.getRange('C12:C13').getValue();
var SPA_Filter_EFF = sheet.getRange('D12:D13').getValue();
var SPACL = sheet.getRange('C15').getValue();
//vvvvvvvvvvv---- Sports med
// Hot Plunge
var HPpHReading = sheet.getRange('E6:E7').getValue();
var HPpHTest = sheet.getRange('F6:F7').getValue();
var HPORP = sheet.getRange('E9:E10').getValue();
var HPSetPoint = sheet.getRange('F9:F10').getValue();
var HPCL = sheet.getRange('E12:E13').getValue();
//vvvvvvvvvvvvv---- Cold Plunge
var CPpHReading = sheet.getRange('G6:G7').getValue();
var CPpHTest = sheet.getRange('H6:H7').getValue();
var CPORP = sheet.getRange('G9:G10').getValue();
var CPSetPoint = sheet.getRange('H9:H10').getValue();
var CPCL = sheet.getRange('G12:G13').getValue();
//vvvvvvvvvvvv---Swim EX
var SEpHReading = sheet.getRange('I6:I7').getValue();
var SEpHTest = sheet.getRange('J6:J7').getValue();
var SEORP = sheet.getRange('I9:I10').getValue();
var SESetPoint = sheet.getRange('J9:10').getValue();
var SECL = sheet.getRange('I12:I13').getValue();
//vvvvvvvvvvvv---ODP
var ODPpHReading = sheet.getRange('K6:K7').getValue();
var ODPpHTest = sheet.getRange('L6:L7').getValue();
var ODPORP = sheet.getRange('K9:K10').getValue();
var ODPSetPoint = sheet.getRange('L9:L10').getValue();
var ODPCL = sheet.getRange('k12:k13').getValue();
// email addresses for people and subject
var emailAddress = " PseudoMcFake@Notreal.noe";
var subject = "Abnormal Readings";
var view = "link";
// if soemthing is "wrong" then it changes this to true. At the end, all trues will be added to the email list
var needsCheck = false;
var message = 'An Aquatic Specialist recently logged chemical readings that were off. Here is a list for your convinience:\n';
//-------------------- IDP pH
if (IDPpHReading > 7.8) {
var message = message + " \n IDP - ph Controller reading was too high at " + IDPpHReading ;
var needsCheck = true;
}
else if (IDPpHReading < 7.2) {
var message = message + " \n IDP - ph Controller reading was too low at " + IDPpHReading
var needsCheck = true;
}
if (IDPpHTest > 7.8) {
;
var message = message + " \n IDP - pH Test was too high at " + IDPpHReading
var needsCheck = true;
}
else if (IDPpHTest < 7.2) {
var message = message + " \n IDP - pH Test was too low at " + IDPpHReading
var needsCheck = true;
}
//-------------------------------------------------------
//-------------------------------------------------- Chlorine/ORP IDP
if ( IDPORP >= IDPSetPoint + 20) {
var message = message + " \n IDP - ORP reading was too high at " +IDPORP;
var needsCheck = true;
}
else if ( IDPORP <= IDPSetPoint - 20) {
var message = message + " \n IDP - ORP reading was too low at " + IDPORP;
var needsCheck = true;
}
if ( IDPCL < 1) {
var message = message + " \n IDP - Chlorine was too low at " + IDPCL;
var needsCheck = true;
}
else if ( IDPCL > 5 || !isNaN(IDPCL) ) {
var message = message + " \n IDP - Chlorine was too high at " + IDPCL;
var needsCheck = true;
}
else if ( isNaN(IDPCL))
{
var message = message + " \n Spa - Chlorine reading was an 'error'. Might be too high. User input = " + IDPCL;
var needsCheck = true;
}
//---------------------------------------------------------------
//---------------------------------------------- Filters
if ( IDP_Filter1_INF - IDP_Filter1_EFF >=10 || IDP_Filter1_EFF - IDP_Filter1_INF >= 10)
{
;
var message = message + " \n IDP - Differential greater than or equal to 10 for filter 1";
var needsCheck = true;
}
if ( IDP_Filter2_INF - IDP_Filter2_EFF >=10 || IDP_Filter2_EFF - IDP_Filter2_INF >= 10)
{
var message = message + " \n IDP - Differential greater than or equal to 10 for filter 2";
var needsCheck = true;
}
//-------SPA----------------------------------------------
if (SPApHReading > 7.8) {
var message = message + " \n SPA - pH Reading too high at " + SPApHReading;
var needsCheck = true;
}
else if (SPApHReading < 7.2) {
var message = message + " \n SPA - pH Reading was too low at " + SPApHReading;
var needsCheck = true;
}
if ( SPApHTest > 7.8) {
var message = message + " \n SPA - pH test was too high at " + SPApHTest;
var needsCheck = true;
}
else if ( SPApHTest < 7.2) {
var message = message + " \n SPA - pH test was too low at " + SPApHTest;
var needsCheck = true;
}
//-------------------------------------------------------
//-------------------------------------------------- Chlorine/ORP SPA
if ( SPAORP >= SPASetPoint + 20) {
var message = message + " \n SPA - ORP reading was too high at " + SPAORP;
var needsCheck = true;
}
else if ( SPAORP <= SPASetPoint - 20) {
var message = message + " \n SPA - ORP reading was too low at " + SPAORP;
var needsCheck = true;
}
if ( SPACL < 2) {
var message = message + " \n SPA - Chlorine was too low at " + SPACL;
var needsCheck = true;
}
else if ( SPACL > 5) {
var message = message + " \n SPA - Chlorine was too high at " + SPACL;
var needsCheck = true;
}
else if ( isNaN(SPACL))
{
var message = message + " \n Spa - Chlorine reading was an 'error'. Might be too high. User input = " + SPACL;
var needsCheck = true;
}
//---------------------------------------------------------------------------------------
// Sports Med Hot Plunge ------------------------
if (HPpHReading > 7.8) {
var message = message + " \n HP - pH reading was too high at " + HPpHReading;
var needsCheck = true;
}
else if (HPpHReading < 7.2) {
var message = message + " \n HP - pH reading was too low at " + HPpHReading;
var needsCheck = true;
}
if ( HPpHTest > 7.8) {
var message = message + " \n HP - pH Test was too high at " + HPpHTest;
var needsCheck = true;
}
else if ( HPpHTest < 7.2) {
var message = message + " \n HP - pH Test was too low at " + HPpHTest;
var needsCheck = true;
}
if ( HPORP >= HPSetPoint + 20) {
var message = message + " \n HP - ORP reading was too high at " + HPORP;
var needsCheck = true;
}
else if ( HPORP <= HPSetPoint - 20) {
var message = message + " \n HP - ORP reading was too low at " + HPORP;
var needsCheck = true;
}
if ( HPCL > 5) {
var message = message + " \n HP - Chlorine was too low at " + HPCL;
var needsCheck = true;
}
else if ( HPCL < 2) {
var message = message + " \n HP - Chlorine was too low at " + HPCL;
var needsCheck = true
}
else if ( isNaN(HPCL))
{
var message = message + " \n HP - Chlorine reading was an 'error'. Might be too high. User input = " + HPCL;
var needsCheck = true;
}
//-------------------------------------------------------
// Cold Plunge
if (CPpHReading > 7.8) {
var message = message + " \n Cold Plunge - pH Reading was too High at " + CPpHReading ;
var needsCheck = true;
}
else if (CPpHReading < 7.2) {
var message = message + " \n Cold Plunge - pH Reading was too low at " + CPpHReading ;
var needsCheck = true;
}
if ( CPpHTest > 7.8) {
var message = message + " \n Cold Plunge - pH Test was too High at " + CPpHTest ;
var needsCheck = truel
}
else if ( HPpHTest < 7.2) {
var message = message + " \n Cold Plunge - pH Test was too low at " + CPpHTest ;
var needsCheck = true
}
if ( CPORP >= CPSetPoint + 20) {
var message = message + " \n Cold Plunge - ORP reading was too High at " + CPORP ;
var needsCheck = true;
}
else if ( CPORP <= CPSetPoint - 20) {
;
var message = message + " \n Cold Plunge - ORP reading was too low at " + CPORP ;
var needsCheck = true;
}
if ( CPCL > 8) {
var message = message + " \n Cold Plunge - Chlorine was too High at " + CPCL ;
var needsCheck = true;
}
else if ( CPCL < 2.5) {
var message = message + " \n Cold Plunge - Chlorine was too low at " + CPCL ;
var needsCheck = true;
}
else if ( isNaN(CPCL))
{
var message = message + " \n Cold Plunge - Chlorine reading was an 'error'. Might be too high. User input = " + CPCL;
var needsCheck = true;
}
//----------------------------------------------
// Swim EX
if (SEpHReading > 7.8) {
var message = message + " \n Swim EX - pH Reading was too High at " + SEpHReading ;
var needsCheck = true;
}
else if (SEpHReading < 7.2) {
var message = message + " \n Swim EX - pH Reading was too low at " + SEpHReading ;
var needsCheck = true;
}
if ( SEpHTest > 7.8) {
var message = message + " \n Swim EX - pH Test was too High at " + SEpHTest ;
var needsCheck = true;
}
else if ( SEpHTest < 7.2) {
var message = message + " \n Swim EX - pH Test was too low at " + SEpHTest ;
var needsCheck = true;
}
if ( SEORP >= CPSetPoint + 20) {
var message = message + " \n Swim EX - ORP reading was too High at " + SEORP ;
var needsCheck = true;
}
else if ( SEORP <= CPSetPoint - 20) {
var message = message + " \n Swim EX - ORP reading was too low at " + SEORP ;
var needsCheck = true;
}
if ( SECL > 8) {
var message = message + " \n Swim EX - Chlorine was too High at " + SECL ;
var needsCheck = true;
}
else if ( SECL < 2.5) {
var message = message + " \n Swim EX - Chlorine was too low at " + SECL ;
var needsCheck = true;
}
else if ( isNaN(SECL))
{
var message = message + " \n Swim EX - Chlorine reading was an 'error'. Might be too high. User input = " + SECL;
var needsCheck = true;
}
//------------------------------------------------------------------------------------
// ------------------ ODP
if (ODPpHReading > 7.8) {
var message = message + " \n ODP - pH Reading was too High at " + ODPpHReading ;
var needsCheck = true;
}
if (ODPpHReading < 7.2) {
var message = message + " \n ODP - pH Reading was too low at " + ODPpHReading ;
var needsCheck = true;
}
if ( ODPpHTest > 7.8) {
var message = message + " \n OFP - pH Test was too High at " + ODPpHTest ;
var needsCheck = true;
}
else if ( ODPpHTest < 7.2) {
var message = message + " \n ODP - pH Test was too low at " + ODPpHTest ;
var needsCheck = true;
}
if ( ODPORP >= ODPSetPoint + 20) {
var message = message + " \n ODP - ORP reading was too High at " + ODPORP ;
var needsCheck = true;
}
else if ( ODPORP <= CPSetPoint - 20) {
var message = message + " \n ODP - ORP reading was too low at " + ODPORP ;
var needsCheck = true;
}
if ( ODPCL > 5) {
var message = message + " \n ODP - Chlorine was too High at " + ODPCL ;
var needsCheck = true;
var ODPCL_2 = ODPCL;
}
else if ( ODPCL < 2) {
var message = message + " \n ODP - Chlorine was too low at " + ODPCL ;
var needsCheck = true;
}
else if ( isNaN(ODPCL))
{
var message = message + " \n ODP - Chlorine reading was an 'error'. Might be too high. User input = " + ODPCL;
var needsCheck = true;
}
if ( needsCheck)
{
var message = message + "\n Please check the situation asap. \n Here is a link to the spreadsheet - " + view;
MailApp.sendEmail(emailAddress, subject, message);
}
};
编辑:
我在考虑做类似
的事情var IDP&Spa_LastRow = getLastRow();
var Previous_IDP&SPA = getLastRow() - 1;
但......问题在于有人提交另一份表格。