【问题标题】:Is it possible to send a google form with a trigger from a spreadsheet value?是否可以发送带有电子表格值触发器的谷歌表单?
【发布时间】:2013-06-30 02:28:15
【问题描述】:

是否可以发送带有电子表格值触发器的 Google 表单?如果是这样,我该去哪里寻求帮助?

我创建了一个可以在此处查看的谷歌表单http://www.leadersoftomorrowisn.org/Become_a_Member.html

我希望能够从问题 5“您对什么感兴趣?”中获得答案。并使用它们发送特定的 Google 表单。

是否可以发送带有电子表格值触发器的 Google 表单?如果是这样,我该去哪里寻求帮助?

最好, 麦克斯韦

【问题讨论】:

    标签: triggers google-apps-script google-sheets google-forms


    【解决方案1】:

    假设您的成为会员表单有一个接收响应的电子表格,并且您将创建一个带有Form Response 触发器的脚本,该触发器将在响应出现时对其进行审查。我们将调用该触发器onFormSubmit()。您可以选择创建包含在表单脚本或电子表格脚本中的触发函数 - 这些容器中的任何一个都可以接收表单响应。此选择将决定 onFormSubmit() 将接收哪个事件 - 有关详细信息,请参阅 Understanding Events

    您将针对您的兴趣范围创建(或已经拥有)一组额外的 Google 表单。这些表单中的每一个都有一个唯一的 ID,您将使用它来获取您将发送给受访者的表单的 URL。有关 API 详细信息,请参阅Class FormApp。对于您的每个兴趣表单,您需要将唯一 ID 嵌入到脚本中 - 当您在表单编辑器或 Live Form 中时,该 ID 会显示在 URL 中。

    onFormSubmit 中,您可以使用表单提交事件来读取当前响应的副本。您的问题 5 是 checkBox 问题,因此所有检查的答案都将以逗号分隔的字符串形式提供。 (注意不要在您的问题中使用逗号!)在下面的示例中,我们将splitting 对问题 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,其中已经填写了受访者的姓名。

    【讨论】:

      猜你喜欢
      • 2015-05-06
      • 1970-01-01
      • 1970-01-01
      • 2018-03-14
      • 2015-09-12
      • 2018-06-08
      • 2021-01-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多