【问题标题】:Google Apps Script typeError in Google Form to Google ContactsGoogle Apps Script typeError in Google Form to Google Contacts
【发布时间】:2021-12-27 05:20:00
【问题描述】:

我一直在关注 YouTube 上的“学习 Google 电子表格的视频“Google 表单到 Google 联系人(Gmail 联系人)”以创建类似的功能,但我不断收到“
TypeError:无法读取属性”未定义的 addContact @ ... 的名字'。

ContactsApp.createContact 需要 3 个字符串,我相信这就是我提供的内容。所以我的想法是单元格引用是问题所在,但我不知道如何测试 info['First name'] 的结果。

非常感谢任何帮助:)

function addContact(info) {

  const c = ContactsApp.createContact(info['First name'],info['Last name'],info['Email']);
  const cg = ContactsApp.getContactGroups();

  c.addToGroup(cg[4]);

}
Timestamp Email First name Last name
11/14/2021 20:51:11 jane_doe@email.com Jane Doe

电子表格由 Google 表单填充。

【问题讨论】:

  • 您的表中似乎有错误的数据。电子邮件中应该有一封电子邮件。列对齐和数据有问题

标签: google-apps-script typeerror google-forms google-contacts-api


【解决方案1】:

如果您正在运行 onForSubmit 触发器,则此行:

const c = ContactsApp.createContact(info['First name'],info['Last name'],info['Email']);

应该是

const c = ContactsApp.createContact(info.namedValues['First name'][0], info.namedValues['Last name'][0], info.namedValues['Email'][0]);

假设您的其余代码是正确的,它应该看起来像这样,因为我们通常使用 e 作为触发事件对象替换参数

function addContact(e) {
  const c = ContactsApp.createContact(e.namedValues['First name'][0],e.namedValues['Last name'][0],e.namedValues['Email'][0]);
  const cg = ContactsApp.getContactGroups();
  c.addToGroup(cg[4]);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-08
    • 1970-01-01
    • 1970-01-01
    • 2015-02-22
    • 1970-01-01
    • 2022-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多