私はhereというGoogleフォーム確認メールトリガーを設定しました。その間、接続された回答シートは、提出ごとに別の列(私の場合は列B)で一意のIDを計算します。式は、hereです。リンクされたシートからの情報を含むGoogleフォーム確認メール
私が達成したいのは、この一意のIDを確認メールに挿入することです。問題は、Formsスクリプトで適切な[シート]フィールドを参照する方法がわからないことです。
私はe.values[1]
で実験しましたが、動作させることができません。
function setup() {
/* First, delete all previous triggers */
var triggers = ScriptApp.getProjectTriggers();
for (var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
/* Then add a trigger to send an email on form submit */
ScriptApp.newTrigger("sendConfirmationEmail")
.forForm(FormApp.getActiveForm())
.onFormSubmit()
.create();
}
function sendConfirmationEmail(e) {
// e is a Form Event object - see https://developers.google.com/apps-script/guides/triggers/events#google_forms_events
// Edit this to set the subject line for the sent email
var subject = "Data Entry Successful";
// This will show up as the sender's name
var sendername = "John Smith";
// This is the body of the registration confirmation message
var message = "Thank you for submitting the details of your project!<br><br>";
message += "Your form responses were:<br><br>";
// response is a FormResponse - see https://developers.google.com/apps-script/reference/forms/form-response
var response = e.response;
var textbody, sendTo, bcc;
// Get the script owner's email address, in order to bcc: them
bcc = Session.getActiveUser().getEmail();
// Now loop around, getting the item responses and writing them into the email message
var itemResponses = response.getItemResponses();
for (var i = 0; i < itemResponses.length; i++) {
var itemResponse = itemResponses[i];
message += itemResponse.getItem().getTitle() +": " + itemResponse.getResponse() + "<br>";
// If this field is the email address, then use it to fill in the sendTo variable
// Check that your form item is named "Please enter your email address" or edit to match
if (itemResponse.getItem().getTitle() == "Please enter your email address") {
sendTo = itemResponse.getResponse();
}
}
message += "<br><a href=\"" + response.getEditResponseUrl() + "\">Please click here</a> if you wish to edit your data or include additional details at a later date.<br>It is essential that you submit any editing through this provided link, since your response data is exclusive only to you. Please do not share your unique edit link with others.<br>If the link doesn't work properly, please copy the following link address manually and then paste it directly into your browser's URL bar:<br>" + response.getEditResponseUrl() + "<br><br><br>Sincerely,<br>John Smith";
message += "<br><br>";
textbody = message.replace("<br>", "\n");
GmailApp.sendEmail(sendTo, subject, textbody,
{bcc: bcc, name: sendername, htmlBody: message});
}
そして、これが私の目標を達成するために私の試みである、しかし、それは動作しません:ここで
は、シートへの参照(この1つの機能完璧)whithoutスクリプトがある
function setup() {
/* First, delete all previous triggers */
var triggers = ScriptApp.getProjectTriggers();
for (var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
/* Then add a trigger to send an email on form submit */
ScriptApp.newTrigger("sendConfirmationEmail")
.forForm(FormApp.getActiveForm())
.onFormSubmit()
.create();
}
function sendConfirmationEmail(e) {
// e is a Form Event object - see https://developers.google.com/apps-script/guides/triggers/events#google_forms_events
// Edit this to set the subject line for the sent email
var subject = "Data Entry Successful";
// This will show up as the sender's name
var sendername = "John Smith";
// This is the body of the registration confirmation message
var message = "Thank you for submitting the details of your project!<br><br>";
message += "Your form responses were:<br><br>";
// response is a FormResponse - see https://developers.google.com/apps-script/reference/forms/form-response
var response = e.response;
var textbody, sendTo, bcc;
// Get the script owner's email address, in order to bcc: them
bcc = Session.getActiveUser().getEmail();
// Get the sheet-generated ID of the submission
var activitID = e.values[1]; //ID number from column B
// Now loop around, getting the item responses and writing them into the email message
var itemResponses = response.getItemResponses();
for (var i = 0; i < itemResponses.length; i++) {
var itemResponse = itemResponses[i];
message += itemResponse.getItem().getTitle() +": " + itemResponse.getResponse() + "<br>";
// If this field is the email address, then use it to fill in the sendTo variable
// Check that your form item is named "Please enter your email address" or edit to match
if (itemResponse.getItem().getTitle() == "Please enter your email address") {
sendTo = itemResponse.getResponse();
}
}
message += "The ID of the submitted activity is: " + activitID + "<br><br><a href=\"" + response.getEditResponseUrl() + "\">Please click here</a> if you wish to edit your data or include additional details at a later date.<br>It is essential that you submit any editing through this provided link, since your response data is exclusive only to you. Please do not share your unique edit link with others.<br>If the link doesn't work properly, please copy the following link address manually and then paste it directly into your browser's URL bar:<br>" + response.getEditResponseUrl() + "<br><br><br>Sincerely,<br>John Smith";
message += "<br><br>";
textbody = message.replace("<br>", "\n");
GmailApp.sendEmail(sendTo, subject, textbody,
{bcc: bcc, name: sendername, htmlBody: message});
}
2つのactivitID
部分をコードに追加し、もう1つを受信者に送信するメッセージに追加しました。
どのように私はこの仕事をすることができますか?
は、答えをutphxをありがとうございました。悲しいことに、あなたの答えはスクリプトを動作させるものではありません。私はそれを変更し、応答シートのタイトルを変更しましたが、電子メールは送信されませんでした。私のこれまでの試みと同様に、これは機能を壊すようです。 – mozzribo
あなたの前提を明確にする:はい、一意のIDは応答と同じ行にあります。 – mozzribo
エラーの実行記録をチェックできますか?または、Logger.log(activitID)を試してIDが取得されているかどうか確認してください – utphx