Answer the question
In order to leave comments, you need to log in
How do I set up an autoresponder for filling out forms in different languages?
Hello! I set up, according to the instructions on Google Script, sending an autoresponder with a welcome letter like this.
function sendFormByEmail(e)
{
// instance of Active Spreadsheet:
var responceSheet = SpreadsheetApp.getActiveSheet();
// number of rows in responce form:
var rows = responceSheet.getLastRow();
// range of names, e-mails:
var namesRange = responceSheet.getRange(rows, 2, 1, 1);
var surnamesRange = responceSheet.getRange(rows, 3, 1, 1);
var emailsRange = responceSheet.getRange(rows, 8, 1, 1);
// last sender's name, e-mail::
var nameSender = namesRange.getValue();
var surnameSender = surnamesRange.getValue();
var emailSender = emailsRange.getValue();
// message ReplyTo, subject, body:
var emailReplyTo = "[email protected]";
var subject = "Спасибо за Ваш интерес";
var body = "<b>Здравствуйте, " + nameSender + surnameSender + "!</b> <br> Спасибо, что Вы с нами :)";
// send the e-mails:
MailApp.sendEmail({to: emailSender, replyTo: emailReplyTo, subject: subject, htmlBody: body});
}
// The code below will make the 2nd sheet active in the active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
SpreadsheetApp.setActiveSheet(ss.getSheets()[1]);
Answer the question
In order to leave comments, you need to log in
This code will never work for you. Read the comments on the resource you provided.
The main mistake is a reference to an active Table SpreadsheetApp.getActiveSpreadsheet();
A trigger OnFormSubmit
cannot have an active Table because no user has opened it. And even if he opened it, then he may not be a trigger registrar or its initiator.
Error Handling
Google Apps Script (we are talking about this point in time in the development of the language) does not have advanced debugging methods. So wrap the main call:
/**
* В Таблице должен быть лист "Лог".
* Чтобы лист существовал всегда
* https://github.com/oshliaer/google-apps-script-snippets#get-a-sheet-by-name
**/
function handler(e) {
try {
sendFormByEmail(getNewEmailMessage(e));
} catch(err) {
e.source.getSheetByName('Лог').appendRow([new Date(), err.message, err.stack]);
}
}
e.source.getSheetByName()
. That's all it takes. /**
* Определение языка на основе ответа
**/
function getNewEmailMessage(e) {
var sheet = e.range.getSheet();
var lang = 'EN';
switch(sheet.getName()){
case 'RU':
return 'Ответ на русском';
break;
case 'EN':
return 'Ответ на нерусском';
break;
}
return 'Ответ на русском';
}
sendFormByEmail
according to the accepted parameters. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question