0

I have a main spreadsheet that collects information being submitted. I would like an email containing the data from the submission to be emailed to a specified email address (not the creator of the form) if a specific value is chosen in the entry. I have created a query to pull all of the data for that particular value into a new tab, but I can't find a simple way to get the data from there emailed out to the particular person.
I was trying to work with a few scripts I found around this site but can't seem to find one that fits my needs. The closest I have found was Google script, send email with form details triggered by form submit

Is it easier to bypass the extra sheet and just create a notification to a specified email with form data when a particular value is entered?

Community
  • 1
  • 1

1 Answers1

0

Your question is hard to understand (at least for me), but I think you want to email a spreadsheet to a person.

   function sendyourdata()
   {
           ......
   var userEmail = Session.getActiveUser().getEmail();

   var fileName  = 'name of your Google Spreadsheet';
   var subject   = 'your title';
   var body      = 'your body text';
   var nameXLS   = subject; 

   var excelFile = exportAsExcel(fileName, subject);
   var attached = { attachments: excelFile, name: nameXLS };
   GmailApp.sendEmail(userEmail, subject, body, attached );  
          .....
   }

function exportAsExcel(nameOrigin, nameTarget)
{ // Convert a GOOGLE_SHEETS (spreadsheet)file into an Excel xlsx file
  // http://stackoverflow.com/questions/24985703/converting-google-spreadsheet-to-xlsx-or-ods-using-gas/25205566#25205566
  var file = getSpreadsheetByName(nameOrigin); // function to get a file by its name
  if (file != null)
  {  
     var spreadsheetId = file.getId();
     var file     = Drive.Files.get(spreadsheetId);  // Advanced service needs to be activated
     var url      = file.exportLinks['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
     var token    = ScriptApp.getOAuthToken();
     var response = UrlFetchApp.fetch(url, { headers: { 'Authorization': 'Bearer ' +  token }});
     file = DriveApp.createFile(response.getBlob()).setName(nameTarget);
  }  
  return file;
}

Data you write to a google spreadsheet will be read and written to an excel xlsx file . That file will be send to the active user (or any other emailaddress you provide of course).
If you don't want to convert the Google sheet to an excel file you can skip all the code dealing with the conversion.

SoftwareTester
  • 1,048
  • 1
  • 10
  • 25