Reputation: 43
I have this script that sends an email when a new form submission is received. I need to see if there is an easy way to edit this to only send the email on a form submission when value 4 = Fail Can anybody help me? I can't even guess where to begin as this script was written for me by someone here.
function triggermenu() {
SpreadsheetApp.getUi().createMenu('Trigger Menu')
.addItem('Create Trigger', 'createFormSubmitTrigger')
.addToUi();
}
function createFormSubmitTrigger(funcname) {
var funcname=funcname||'form1Submit';
if(!isTrigger(funcname)) {
ScriptApp.newTrigger(funcname).forSpreadsheet(SpreadsheetApp.getActive()).onFormSubmit().create();
}
}
function form1Submit(e) {
if(e.values && e.values[1] && e.values[2]) {
var html='<style>td,th{padding:overflow-wrap: break-word;}table{table-layout:fixed;width:100%;}</style><table>';
html+=Utilities.formatString('<tr><td>%s</td><td style="width:20%;" colspan ="2"><font size="4" color="red"><b>%s</b></font></td><td style="width:80%;">%s</td></tr>',' ','**** DO NOT REPLY TO THIS EMAIL ****',' ' );
html+=Utilities.formatString('<tr><td>%s</td><td style="width:20%;">%s</td><td style="width:80%;">%s</td></tr>',' ',' ',' ' );//empty line
html+=Utilities.formatString('<tr><td>%s</td><td style="width:20%;">%s</td><td style="width:80%;">%s</td></tr>',' ',' ',' ' );//empty line
html+=Utilities.formatString('<tr><td>%s</td><td style="width:20%;" colspan ="2">%s</td><td style="width:80%;">%s</td></tr>',' ','Please review findings',' ' );
html+=Utilities.formatString('<tr><td>%s</td><td style="width:20%;" colspan ="2"><font size="5"><b>%s</b></font></td><td style="width:80%;">%s</td></tr>',' ','VISUAL WELDING AUDIT',' ' );
html+=Utilities.formatString('<tr><td>%s</td><td style="width:20%;"><strong>%s</strong></td><td style="width:80%;">%s</td></tr>',' ','Date and Time of Audit:',e.values[0]);
html+=Utilities.formatString('<tr><td>%s</td><td style="width:20%;"><strong>%s</strong></td><td style="width:80%;">%s</td></tr>',' ','Auditor:',e.values[1]);
html+=Utilities.formatString('<tr><td>%s</td><td style="width:20%;"><strong>%s</strong></td><td style="width:80%;">%s</td></tr>',' ','Line/Location Audited:',e.values[2]);
html+=Utilities.formatString('<tr><td>%s</td><td style="width:20%;"><strong>%s</strong></td><td style="width:80%;">%s</td></tr>',' ','Area Responsible:',e.values[3]);
html+=Utilities.formatString('<tr><td>%s</td><td style="width:20%;">%s</td><td style="width:80%;">%s</td></tr>',' ',RoGpf(e.values[4]),RoG(e.values[4]));
html+=Utilities.formatString('<tr><td>%s</td><td style="width:20%;"><strong>%s</strong></td><td style="width:80%;">%s</td></tr>',' ','Person Notified:',e.values[9]);
html+=Utilities.formatString('<tr><td>%s</td><td style="width:20%;"><strong>%s</strong></td><td style="width:80%;">%s</td></tr>',' ','Disposition:',e.values[5]);
html+=Utilities.formatString('<tr><td>%s</td><td style="width:20%;"><strong>%s</strong></td><td style="width:80%;">%s</td></tr>',' ','Discontinuity Found:',e.values[6]);
html+=Utilities.formatString('<tr><td>%s</td><td style="width:20%;"><strong>%s</strong></td><td style="width:80%;">%s</td></tr>',' ','Safety Findings Comment:',e.values[7]);
html+=Utilities.formatString('<tr><td>%s</td><td style="width:20%;"><strong>%s</strong></td><td style="width:80%;">%s</td></tr>',' ','Additonal Comments:',e.values[8]);
html+=Utilities.formatString('<tr><td>%s</td><td style="width:20%;">%s</td><td style="width:80%;">%s</td></tr>',' ',' ',' ' );//empty line
html+=Utilities.formatString('<tr><td>%s</td><td style="width:20%;">%s</td><td style="width:80%;">%s</td></tr>',' ',' ',' ' );//empty line
html+=Utilities.formatString('<tr><td>%s</td><td><a href="https://docs.google.com/spreadsheets/d/1tsBcTDVcI1p7GtgTbtgQGdRwerZqlpyWKdEHcT5nNT0/edit?usp=sharing">Link to Dashboard</a></td><td>%s</td></tr>',' ',' ',' ' );
html+='</table>';
Logger.log(html);
GmailApp.sendEmail(getGlobal('form1Email'), getGlobal('form1Subject'), '', {htmlBody:html});
}
}
function RoG(s) {
if(s) {
if(s=='Pass') {
return '<span style="color:#007800;">Pass</span';
}else if(s=='Fail') {
return '<span style="color:#d20000;">Fail</span>';
}
}
return s;
}
function RoGpf(s) {
if(s) {
if(s=='Pass') {
return '<span style="color:#007800;font-weight:bold">Pass/Fail</span';
}else if(s=='Fail') {
return '<span style="color:#d20000;font-weight:bold">Pass/Fail</span>';
}
}
return s;
}
Thank you in advance!
Upvotes: 1
Views: 70
Reputation: 43
This is what worked for me. The IF( at the beginning of the form1sub function now looks like this.
if(e.values && e.values[1] && e.values[2] && e.values[3]=='Fail')
Upvotes: 2