使用自定义字段创建联系人
Create contact with a custom field
我正在尝试使用自定义字段创建联系人,如文档 here 中所述。
所以我尝试使用文档中的这段代码:
var contacts = ContactsApp.getContactsByName('John Doe');
var field = contacts[0].getCustomFields()[0];
field.setLabel('Mail application');
field.setValue('Gmail');
当我 运行 脚本时,出现以下错误:
TypeError: Cannot read property 'setLabel' of undefined
有什么想法吗?
这是我的完整代码,我希望能够向其中添加一个名为“身份证号”的自定义字段:
var clientaddress = spreadsheet.getRange('L2').getValue();
var clientcontact = ContactsApp.createContact(clientfirstname, clientlastname, clientemail);
var contactgroup = spreadsheet.getRange('AL2').getValue(); // AL2 has the group name
var group = ContactsApp.getContactGroup(contactgroup);
clientcontact = clientcontact.addToGroup(group);
var address = clientcontact.addAddress(ContactsApp.Field.HOME_ADDRESS,clientaddress);
var phone = clientcontact.addPhone(ContactsApp.Field.MOBILE_PHONE, clientmobile);
var IDnumber = ?
这是我尝试 运行 作为测试的代码:
function quicktest () {
var contacts = ContactsApp.getContactsByName('XXXX');
var IDnumber = contacts.addCustomField("IDnumber","12345");
}
好的,现在我们知道它是一个数组,我将 [0] 添加到代码中,但仍然没有 joy.I 确保选择了一个没有重复的联系人,所以我会确定它正在编辑正确的联系人。
function quicktest () {
var contacts = ContactsApp.getContactsByName('XXX');
var IDnumber = contacts[0].addCustomField("IDnumber","12345");
}
这是联系人“更多详细信息”页面的屏幕截图。
是的,现在可以使用了:)
谢谢大家!
修改后的代码:
function quicktest () {
var contacts = ContactsApp.createContact("test1", "familytest1", "email@email.com").getId();
ContactsApp.getContactById(contacts).addCustomField("IDnumber","12345");
}
来自 Google 联系人的屏幕截图:
field.setLabel('Mail application');
Cannot read property 'setLabel' of undefined
错误表明 field
是 undefined
并且它无法读取 undefined
中名为 setLabel
的 属性(因为 undefined
没有这样的方法;只有 customField class 有)。
field
是 undefined
,因为联系人“John Doe”没有与之关联的自定义字段。
使用Contact.addCustomField("fieldName","fieldValue")
向联系人添加自定义字段:
clientcontact.addCustomField("IDnumber","12345");
我正在尝试使用自定义字段创建联系人,如文档 here 中所述。 所以我尝试使用文档中的这段代码:
var contacts = ContactsApp.getContactsByName('John Doe');
var field = contacts[0].getCustomFields()[0];
field.setLabel('Mail application');
field.setValue('Gmail');
当我 运行 脚本时,出现以下错误:
TypeError: Cannot read property 'setLabel' of undefined
有什么想法吗?
这是我的完整代码,我希望能够向其中添加一个名为“身份证号”的自定义字段:
var clientaddress = spreadsheet.getRange('L2').getValue();
var clientcontact = ContactsApp.createContact(clientfirstname, clientlastname, clientemail);
var contactgroup = spreadsheet.getRange('AL2').getValue(); // AL2 has the group name
var group = ContactsApp.getContactGroup(contactgroup);
clientcontact = clientcontact.addToGroup(group);
var address = clientcontact.addAddress(ContactsApp.Field.HOME_ADDRESS,clientaddress);
var phone = clientcontact.addPhone(ContactsApp.Field.MOBILE_PHONE, clientmobile);
var IDnumber = ?
这是我尝试 运行 作为测试的代码:
function quicktest () {
var contacts = ContactsApp.getContactsByName('XXXX');
var IDnumber = contacts.addCustomField("IDnumber","12345");
}
好的,现在我们知道它是一个数组,我将 [0] 添加到代码中,但仍然没有 joy.I 确保选择了一个没有重复的联系人,所以我会确定它正在编辑正确的联系人。
function quicktest () {
var contacts = ContactsApp.getContactsByName('XXX');
var IDnumber = contacts[0].addCustomField("IDnumber","12345");
}
这是联系人“更多详细信息”页面的屏幕截图。
是的,现在可以使用了:) 谢谢大家! 修改后的代码:
function quicktest () {
var contacts = ContactsApp.createContact("test1", "familytest1", "email@email.com").getId();
ContactsApp.getContactById(contacts).addCustomField("IDnumber","12345");
}
来自 Google 联系人的屏幕截图:
field.setLabel('Mail application');
Cannot read property 'setLabel' of undefined
错误表明 field
是 undefined
并且它无法读取 undefined
中名为 setLabel
的 属性(因为 undefined
没有这样的方法;只有 customField class 有)。
field
是 undefined
,因为联系人“John Doe”没有与之关联的自定义字段。
使用Contact.addCustomField("fieldName","fieldValue")
向联系人添加自定义字段:
clientcontact.addCustomField("IDnumber","12345");