我正在嘗試讓 Google 表單調查的受訪者填寫另一項調查,但他們的一些回復將根據第一次調查預先填寫。基本上,希望他們的所有回答都附加到唯一的人身上,而不是讓他們再次回答相同的問題。它必須是兩次調查,而不是繼續。在這個例子中,我只是預先填寫了他們的電子郵件地址,但它可能是更多的欄位。
所以在 Google Apps Script 中,我有一個 Code.gs 和 Email1.html 腳本,如下所示:
function confirmationEmail1(e) {
var htmlBody= HtmlService.createHtmlOutputFromFile('Email1').getContent();
var recipient=e.response.getRespondentEmail();
if(recipient!==undefined){
MailApp.sendEmail({
to:recipient,
subject: 'Thank you. Please answer another one',
htmlBody: htmlBody,
})
}
}
以及以下電子郵件正文:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<p>Thank you for filling the survey</p>
<p>Now fill another one. Some answers will be pre-filled based on your past responses<p>
<p>To continue click this <a href="https://docs.google.com/forms/d/e/1FAIpQLSfqYWf-V0Jrwh8ld2AjuHtskuEHr1CfQB3_wrLS7grzZ_EajQ/viewform?usp=pp_url&entry.786833434=<?= recipient ?>">Link</a></p>
</body>
</html>
我在這個地方做錯了什么,它沒有從 Code.gs 檢索收件人變數,而是在我的第二次調查中預先填寫了文本“”?
uj5u.com熱心網友回復:
由于htmlBody是一個字串,因此您可以使用方法將任何文本片段替換為另一個文本片段string.replace()。
假設您可以{RECEPIENT}在 html 中制作:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<p>Thank you for filling the survey</p>
<p>Now fill another one. Some answers will be pre-filled based on your past responses<p>
<p>To continue click this <a href="https://docs.google.com/forms/d/e/1FAIpQLSfqYWf-V0Jrwh8ld2AjuHtskuEHr1CfQB3_wrLS7grzZ_EajQ/viewform?usp=pp_url&entry.786833434=<?={RECEPIENT}?>">Link</a></p>
</body>
</html>
然后用腳本中的值替換{RECEPIENT}它的文本recepient:
function confirmationEmail1(e) {
var htmlBody= HtmlService.createHtmlOutputFromFile('Email1').getContent();
var recipient=e.response.getRespondentEmail();
if(recipient!==undefined){
htmlBody = htmlBody.replace('{RECEPIENT}', recipient); // <--- here
MailApp.sendEmail({
to:recipient,
subject: 'Thank you. Please answer another one',
htmlBody: htmlBody,
})
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/481055.html
標籤:javascript html 谷歌应用脚本 谷歌表格
上一篇:如何在GoogleApps腳本中使用DropboxRefreshTokens將DriveFiles傳輸到Dropbox?
下一篇:多個變數中的應用腳本最后一行專案
