Class CustomField

自定义字段

已弃用。请改用 People API 高级服务

联系人中的自定义字段。

方法

方法返回类型简介
getLabel()Object获取此字段的标签。
setLabel(label)CustomField设置此字段的标签。
方法返回类型简介
deleteCustomField()void删除此字段。
getValue()Object获取字段的值。
setLabel(field)CustomField设置此字段的标签。
setValue(value)CustomField设置此字段的值。

详细文档

getLabel()

获取此字段的标签。这可以是 Field、ExtendedField 或 String。

// Logs the label for all the address fields associated with contact
// 'John Doe'. This method can be similarly called for any field that has
// a label.
const contacts = ContactsApp.getContactsByName('John Doe');
const addressFields = contacts[0].getAddresses();
for (let i = 0; i < addressFields.length; i++) {
  Logger.log(addressFields[i].getLabel());
}

返回

Object - 此字段的标签

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

setLabel(label)

设置此字段的标签。

// Sets the label to 'Apartment' for the first address field associated
// with contact 'John Doe'. This method can be similarly called for any
// field that has a label.
const contacts = ContactsApp.getContactsByName('John Doe');
const addressFields = contacts[0].getAddresses();
addressFields[0].setLabel('Apartment');

参数

名称类型说明
labelString此字段的新标签

返回

CustomField - this 字段,适用于链式调用

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

已弃用的方法

已弃用。此函数已废弃,不应在新脚本中使用。

删除此字段。

const contacts = ContactsApp.getContactsByName('John Doe');
const fields = contacts[0].getCustomFields();
for (let i = 0; i < fields.length; i++) {
  if (fields[i].getLabel() === 'foo') {
    fields[i].deleteCustomField();
  }
}

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

已弃用。此函数已废弃,不应在新脚本中使用。

获取字段的值。

// Logs the value of all the custom fields for contact 'John Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const fields = contacts[0].getCustomFields();
for (const i in fields) {
  Logger.log(fields[i].getValue());
}

返回

Object - 存储在字段中的值

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

已弃用。此函数已废弃,不应在新脚本中使用。

设置此字段的标签。

// Sets the first custom field associated with contact 'John Doe' to use 'Mail
// application' as a label, with 'Gmail' as the value.
const contacts = ContactsApp.getContactsByName('John Doe');
const field = contacts[0].getCustomFields()[0];
field.setLabel('Mail application');
field.setValue('Gmail');

参数

名称类型说明
fieldExtendedField新标准标签

返回

CustomField - this 字段,适用于链式调用

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

已弃用。此函数已废弃,不应在新脚本中使用。

设置此字段的值。

// Sets the first custom field associated with contact 'John Doe' to use 'Mail
// application' as a label, with 'Gmail' as the value.
const contacts = ContactsApp.getContactsByName('John Doe');
const field = contacts[0].getCustomFields()[0];
field.setLabel('Mail application');
field.setValue('Gmail');

参数

名称类型说明
valueObject新值

返回

CustomField - this 字段,适用于链式调用

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds