是否可以通过电子表格值发送带有触发器的Google表单? [英] Is it possible to send a google form with a trigger from a spreadsheet value?

查看:81
本文介绍了是否可以通过电子表格值发送带有触发器的Google表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过电子表格值发送带有触发器的Google表单?如果可以,我将在哪里寻求帮助?

Is it possible to send a google form with a trigger from a spreadsheet value? if so where would I go for help?

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

I Have created a google form that can be viewed here http://www.leadersoftomorrowisn.org/Become_a_Member.html

我希望能够问题5您对什么感兴趣?的回复并使用它们发送特定的Google表单。

I want to be able to take the responses from question 5 "What Are You interested in?" and use them to send out specific google forms.

是否可以通过电子表格值发送带有触发器的Google表单?

Is it possible to send a google form with a trigger from a spreadsheet value? if so where would I go for help with that?

最好,
Maxwell

Best, Maxwell

推荐答案

让我们假定您的成为会员表单具有接收响应的电子表格,并且您将使用表单响应触发器,它将在响应出现时进行审核。我们将其称为 onFormSubmit()触发器。您可以选择创建包含在表单脚本或电子表格脚本中的触发函数-这些容器中的任何一个都可以接收表单响应。此选择将决定 onFormSubmit()将接收哪个事件-请参见了解事件

Let's assume that your Become a Member form has a spreadsheet that receives responses, and that you will create a script with a Form Response trigger that will review the responses as they come. We'll call that trigger onFormSubmit(). You have the option to create this trigger function contained within a Form Script, or within a Spreadsheet Script - either of those containers can receive the form responses. This choice will dictate which Event will be received by onFormSubmit() - see Understanding Events for details.

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

You will create (or already have) a set of additional Google Forms for the range of interests. Each of these forms has a unique id, and that's what you will use to obtain a URL for the form that you will send to respondents. See Class FormApp for API details. For each of your interest forms, you will need to embed the unique id into the script - that id appears in the URL while you're in the Form Editor, or on the Live Form.

onFormSubmit 中,您可以使用表单提交事件来读取当前响应的副本。您的问题5是一个 checkBox 问题,因此所有选中的答案都将以逗号分隔的字符串形式提供。 (请注意不要在逗号中加逗号!)在下面的示例中,我们将对问题5的回答拆分,以获得一系列兴趣,然后发送电子邮件链接到基于这些调查的其他调查。

In onFormSubmit, you can use the Form Submission Event to read a copy of the current response. Your question 5 is a checkBox question, so all checked answers will be delivered in a comma-delimited string. (Be careful not to have commas in your questions!) In the example below, we're splitting the response to question 5 to get an array of interests, and then sending email links to additional surveys based on those. It's quite crude, and very tightly coupled with your form, but it should do the trick.

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,其中已经填写了受访者的姓名。

You could take this further, for instance you could generate a URL for a pre-filled version of the additional surveys, with the respondent's name already filled in.

这篇关于是否可以通过电子表格值发送带有触发器的Google表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆