I have a google sheet that has two sheets, Form Responses and report: see here
when a form submits report sheet change with the last form or last row of the responses sheet. I want to send an email to the person who submits the form and attach the report sheet as PDF after sending email write sent email in column e: see here
email to: Form Responses column b subject: some text and Form Responses column a cc: [email protected] body: some text and Form Responses column f attach: report sheet as PDF
i used this code but it doesn't work
function onSubmit(e){
Logger.log('submit ran');
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var lastRow = sheet.getLastRow();
var sa = sheet.getRange(lastRow, 1).getValue();
var sB = sheet.getRange(lastRow, 2).getValue();
var sf = sheet.getRange(lastRow, 6).getValue();
var ssID = SpreadsheetApp.getActiveSpreadsheet().getId();
var sheetgId = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getSheetId();
var email = Session.getUser().getEmail();
var subject = SB;
var body = Sf;
var url = "https://docs.google.com/spreadsheets/d/e/..............................................................=0&single=true&output=pdf";
var result = UrlFetchApp.fetch(url)
var contents = result.getContent();
if (emailSent !== "EMAIL_SENT") {
MailApp.sendEmail(email,subject ,body, {attachments:[{fileName:SB+".pdf", content:contents, mimeType:"application//pdf"}]});
sheet.getRange().setValue("EMAIL_SENT");
SpreadsheetApp.flush();
}
}
I get the url from spreadsheet>file>publish to web>publish report tab as pdf
i rewrite the code but get error "TypeError: report.getAs is not a function (line 36, file "Code")"
function onSubmit(e){
Logger.log('submit ran');
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var calculate = ss.getSheets()[2];
var Responses = ss.getSheets()[0];
var report = ss.getSheets()[1];
var lastRow = Responses.getLastRow();
var sa = sheet.getRange(lastRow, 1).getValue();
var sB = sheet.getRange(lastRow, 2).getValue();
var se = sheet.getRange(lastRow, 5).getValue();
var sf = sheet.getRange(lastRow, 6).getValue();
var sh = sheet.getRange(lastRow, 8).getValue();
var cell = calculate.getRange("b2");
cell.setFormula(sh);
SpreadsheetApp.flush();
var email = sB;
var subject = "راید ریپورت "+sa;
var body = se;
var calculate = ss.getSheets()[2];
vafunction onSubmit(e){
Logger.log('submit ran');
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var calculate = ss.getSheets()[2];
var Responses = ss.getSheets()[0];
var report = ss.getSheets()[1];
var lastRow = Responses.getLastRow();
var sa = sheet.getRange(lastRow, 1).getValue();
var sB = sheet.getRange(lastRow, 2).getValue();
var se = sheet.getRange(lastRow, 5).getValue();
var sf = sheet.getRange(lastRow, 6).getValue();
var sh = sheet.getRange(lastRow, 8).getValue();
var cell = calculate.getRange("b2");
cell.setFormula(sh);
SpreadsheetApp.flush();
var email = sB;
var subject = "راید ریپورت "+sa;
var body = se;
var calculate = ss.getSheets()[2];
var Responses = ss.getSheets()[0];
var report = ss.getSheets()[1];
var pdf = report.getAs('application/pdf');
MailApp.sendEmail(email,subject ,body, {attachments:[pdf]});
sf.setvalue("EMAIL_SENT");
SpreadsheetApp.flush();
}
r Responses = ss.getSheets()[0];
var report = ss.getSheets()[1];
var pdf = report.getAs('application/pdf');
MailApp.sendEmail(email,subject ,body, {attachments:[pdf]});
sf.setvalue("EMAIL_SENT");
SpreadsheetApp.flush();
}