You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Forms筛选器触发Calendly邀请报错排查求助

问题分析与解决建议

错误根源

TypeError: Cannot read properties of undefined (reading '0') 本质是代码中访问responses[0]时,responses(即e.values)为undefined,或索引对应关系完全错误。结合你调整过邮箱列位置的操作,核心问题有两个:

  1. 手动运行onFormSubmit函数:该函数是触发器专属函数,手动运行时没有事件对象e,e.values自然不存在。
  2. 索引对应错误:e.values的顺序绑定表单问题的提交顺序,而非你调整后的表格列顺序,且e.values[0]默认是提交时间戳,不是邮箱。

具体解决步骤

1. 禁止手动运行触发器函数

onFormSubmit只能通过表单提交触发,手动运行必然报错,所有测试必须通过真实表单提交完成。

2. 修正e.values的索引对应关系

根据你提供的表格截图,表单提交顺序对应的e.values索引应为:

  • e.values[0]:提交时间戳(固定第一个元素)
  • e.values[1]:邮箱地址
  • e.values[2]:年龄区间
  • e.values[3]:家庭状况
  • e.values[7]:是否愿意参与访谈

3. 增加空值校验避免异常

在访问回答内容前,先校验字段是否存在,防止因未填写必填项导致报错。


修正后的完整代码

function onFormSubmit(e) {
  try {
    // 拦截手动运行的情况
    if (!e || !e.values) {
      Logger.log("请通过表单提交触发此函数,禁止手动运行");
      return;
    }
    
    var responses = e.values;
    
    // 定义筛选条件
    var ageCriteria = ['25-35', '36-45'];
    var familyCriteria = ['Single with Kids.', 'Married/Cohabiting with 1-2 kids.', 'Married/Cohabiting with 3 or more kids.'];
    var interestCriteria = 'Yes';
    
    // 按表单提交顺序获取对应回答
    var recipient = responses[1];
    var ageResponse = responses[2];
    var familyResponse = responses[3];
    var interestResponse = responses[7];
    
    // 校验必填字段是否完整
    if (!recipient || !ageResponse || !familyResponse || !interestResponse) {
      Logger.log("部分必填字段未填写,跳过处理");
      return;
    }
    
    // 检查是否满足筛选条件
    if (ageCriteria.includes(ageResponse) && familyCriteria.includes(familyResponse) && interestResponse === interestCriteria) {
      sendCalendlyInvitation(recipient);
    }
  } catch (error) {
    Logger.log("Error: " + error.toString());
  }
}

function sendCalendlyInvitation(recipient) {
  try {
    var calendlyLink = 'https://calendly.com/pdskains/fake-calendly-interview-link';
    var subject = '访谈邀请';
    var body = '感谢您对我们研究的关注,请点击以下链接预约一对一访谈:' + calendlyLink;
    
    MailApp.sendEmail(recipient, subject, body);
    Logger.log("已向" + recipient + "发送Calendly邀请");
  } catch (error) {
    Logger.log("发送邮件时出错: " + error.toString());
  }
}

额外验证步骤

  1. 检查触发器配置:打开脚本编辑器→左侧「触发器」图标,确认存在onFormSubmit的触发器,触发事件为「表单提交」,关联表单正确。
  2. 测试表单提交:填写完整表单并提交,通过「脚本编辑器→查看→日志」检查是否有错误信息,或是否成功发送邀请邮件。

内容的提问来源于stack exchange,提问作者Paul Skains

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 10:15:06