Class CustomField
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
內容詳盡的說明文件
getLabel()
取得這個欄位的標籤。這可能是欄位、ExtendedField 或字串。
// 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');
參數
| 名稱 | 類型 | 說明 |
label | String | 這個欄位的新標籤 |
回攻員
CustomField:這個欄位可用於鏈結
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.google.com/m8/feeds
已淘汰的方法
deleteCustomField()
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
刪除這個欄位。
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
getValue()
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
取得欄位的值。
// 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
setLabel(field)
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
設定這個欄位的標籤。
// 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');
參數
回攻員
CustomField:這個欄位可用於鏈結
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.google.com/m8/feeds
setValue(value)
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
設定這個欄位的值。
// 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');
參數
回攻員
CustomField:這個欄位可用於鏈結
授權
使用這個方法的腳本需要具備下列一或多個範圍的授權:
-
https://www.google.com/m8/feeds
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[],["The `CustomField` in the Contacts API is deprecated in favor of the People API. It allows interacting with a custom field in a contact, using `getLabel()` to retrieve the field's label and `setLabel(label)` to change it. Deprecated methods include `deleteCustomField()` to remove the field, `getValue()` to get the field's value, `setLabel(field)` to set a label, and `setValue(value)` to assign the field's value. These actions require specific authorization scopes.\n"]]