讓我們假設你的成爲會員形式具有接收響應,並且您將創建一個Form Response觸發,因爲他們來了,是會檢討響應腳本中的電子表格。我們將調用該觸發器onFormSubmit()
。您可以選擇創建包含在表單腳本中或電子表格腳本中的觸發器功能 - 這些容器中的任何一個都可以接收表單響應。此選項將決定onFormSubmit()
將收到哪個事件 - 詳情請參閱Understanding Events。
您將爲一系列興趣創建(或已經擁有)一組額外的Google表單。這些表單中的每一個都有一個唯一的ID,這就是您將用來獲取您將發送給受訪者的表單的URL。有關API的詳細信息,請參閱Class FormApp。對於每個感興趣的表單,您都需要將唯一ID嵌入到腳本中 - 當您在表單編輯器中或Live表單上時,該ID會顯示在URL中。
在onFormSubmit
中,您可以使用表單提交事件來讀取當前響應的副本。你的問題5是一個checkBox
的問題,所以所有檢查的答案將以逗號分隔的字符串提供。 (注意不要在你的問題中使用逗號!)在下面的例子中,我們是split
來回答問題5以獲得一系列興趣,然後根據這些信息發送電子郵件鏈接到其他調查。這非常粗糙,與你的表格非常緊密,但它應該做到這一點。
function onFormSubmit(event) {
// Get the responses into convenient variables.
var firstName = event.values[1]; // Question 1
var lastName = event.values[2]; // Question 2
var email = event.values[3]; // Question 3
var allInterests = event.values[5] // Question 5, a comma-separated list,
.split(','); // which we turn into an array
// Loop over all expressed interests, sending surveys
for (var interest in allInterests) {
sendInterestSurvey(firstName, lastName, email, allInterests[interest]);
}
}
/**
* Determine the id for a form that matches the given survey (interest),
* and send an email to the respondent.
*/
function sendInterestSurvey(firstName, lastName, email, survey) {
var surveyFormId = null; // Will fill with appropriate survey ID
// Set serveyFormId according to current value of 'survey'.
switch (survey) {
case "Becoming an LOT Member of the USD Chapter":
surveyFormId = '1234567890abcdefghijklmnopqrstuvwxyz'; // Replace with real form ID
break;
case "Presenting a business idea at one of USD's Business Opportunity Meetings (Spring 2014)":
surveyFormId = '1234567890abcdefghijklmnopqrstuvwxyz'; // Replace with real form ID
break;
// and so on...
default:
// Error handling, or for "other"
break;
}
// Send an email for any interest with a survey form
if (surveyFormId != null) {
var existingForm = FormApp.openById(surveyFormId);
var surveyURL = existingForm.getPublishedUrl();
var surveyTitle = existingForm.getTitle();
// Build Email Body
var body = 'Dear '+firstName+' '+lastName+',<br><br>'; // Dear John Doe,
body += 'Thanks for completing our Member Contact Information.<br><br>';
body += 'You expressed an interest in: ' + survey;
body += ', and we would like to get more details about your interest.<br><br>';
body += 'Please follow <a href="' +surveyURL+ '">this link</a> to complete the survey.<br><br>';
body += 'Thank you!';
MailApp.sendEmail({
to: email,
subject: surveyTitle,
htmlBody: body
});
}
}
你可以進一步利用這個,比如你可能會產生額外的調查預填充版本的URL,已填寫申請人的名字。