Google App Script: Trigger for email and using CC

1.1k views Asked by At

I have a Google Spreadsheet which once populated from a form, I want the user to be emailed back the contents of the form.

Currently it emails the editors of the form but I want to include the person that actually completed the form in the first place, so the ActiveUser.

This is what I currently have which works for the current requirements but any thoughts on how to achieve this additional functionality?

function sendFormByEmail() {
// set Form Submit trigger from Resources above
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ssName = ss.getName();
var editors = ss.getEditors().join(",");
var owner = ss.getOwner().getEmail();
var subject = "SBS Helpline Enquiry " + ss.getSheetValues(ss.getLastRow(),2,1,1) + "            Requires Action";
<BR/>
// 'to' below will be the recipients of the emailed form responses
// can be to = any one of ( editors , owner , custom , test) no quotes
// both sides of the = should be the same color (not including 'var')
var to = ss.getEditors()// AFTER TESTING: change to either editors , owner , custom
// no quotes in above
var responses=ss.getActiveSheet();
var width=responses.getLastColumn();
var headers=responses.getRange(1,1,1,width ).getValues()[0];
var data=responses.getRange(responses.getLastRow(),1,1,width ).getValues()[0];
var message="PLEASE FORWARD THIS ENQUIRY TO THE RELEVANT CONTACTS" + "\n\n";
for(var i=0;i<width;i++){message+=headers[i] + ' = '+ data[i] + "\n\n";};
MailApp.sendEmail(to,subject,message); 
};

This was resolved, used

to=ss.getSheetValues(ss.getActiveSheet().getLastRow(), 8, 1, 1);
1

There are 1 answers

0
eddyparkinson On

There is formEmailer https://sites.google.com/site/formemailer/ It will do what you want without the need to write code.