Reputation: 39
I have a sheet with around 50 columns and am attempting to email the non blank fields in HTML format to a user; but only the NON-Blank fields, here's my code, which returns Null and Non-Null fields, plus I need it to only email out the last form submission, not all of them:
function onFormSubmit(e) {
var ss = e.source;
var sheet = ss.getActiveSheet();
var range = e.range.getA1Notation();
var column = e.range.getColumn();
var row = e.range.getRow();
var values = e.namedValues;
var htmlBody = '<ul>';
for (Key in values) {
var label = Key;
var data = values[Key];
htmlBody += '<li>' + label + ": " + data + '</li>';
};
htmlBody += '</ul>'
var Submitter = 3;
var Submitteremail = sheet.getRange(row,Submitter).getValue();
MailApp.sendEmail({
to: "[email protected]",
replyTo: Submitteremail,
subject,
htmlBody : htmlBody});
Logger.log("checkpoint5");
}
Upvotes: 0
Views: 64
Reputation: 64082
Here's my appended code after your initial help:
function onFormSubmit(e) {
const sh=e.range.getSheet();
var htmlBody='<ol>';
var Url = "https://docs.google.com/xxx";
var Text = "CMF Form Submission Sheet";
for(key in e.namedValues) {
if(e.namedValues[key][0].length>0) {
htmlBody += '<li>' + key + ": " + e.namedValues[key][0] + '</li>';
}
}
htmlBody += '<p>' + '\n' + '\n' + "<a href=\""+ Url + "\">" + Text + "</a>" +
'\n' + '\n' + '\n' + '<p>' + '</ol>' ;
var Submitteremail = e.values[1];
var Type = e.values[6];
var CMFNumber = e.values[0];
var Sub = "A new CMF has been submitted for a " + Type;
MailApp.sendEmail({to:"[email protected]",subject: Sub, replyTo:Submitteremail,
htmlBody:htmlBody});
Logger.log(html);
}
Upvotes: 1