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
— ป้ายกำกับของช่องนี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
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
— ช่องนี้มีประโยชน์สำหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
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();
}
}
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
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
— ค่าที่จัดเก็บในช่อง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
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
— ช่องนี้มีประโยชน์สำหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
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');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
value | Object | ค่าใหม่ |
รีเทิร์น
CustomField
— ช่องนี้มีประโยชน์สำหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.google.com/m8/feeds
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003e\u003ccode\u003eCustomField\u003c/code\u003e is deprecated and the People API advanced service should be used instead.\u003c/p\u003e\n"],["\u003cp\u003eIt represents a custom field within a Contact and previously allowed for getting, setting, and deleting custom field data.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetLabel()\u003c/code\u003e and \u003ccode\u003esetLabel(label)\u003c/code\u003e methods remain available for retrieving and setting the label of a custom field.\u003c/p\u003e\n"],["\u003cp\u003eSeveral methods, including \u003ccode\u003edeleteCustomField()\u003c/code\u003e, \u003ccode\u003egetValue()\u003c/code\u003e, \u003ccode\u003esetLabel(field)\u003c/code\u003e, and \u003ccode\u003esetValue(value)\u003c/code\u003e, are deprecated and should no longer be used.\u003c/p\u003e\n"]]],["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"],null,["# Class CustomField\n\nCustomField\n\n\n**Deprecated.** Instead, use the [People API advanced\nservice](/apps-script/advanced/people)\n\nA custom field in a Contact. \n\n### Methods\n\n| Method | Return type | Brief description |\n|--------------------------------------|------------------|--------------------------------|\n| [getLabel()](#getLabel()) | `Object` | Gets the label for this field. |\n| [setLabel(label)](#setLabel(String)) | [CustomField](#) | Sets the label of this field. |\n\n### Deprecated methods\n\n| Method | Return type | Brief description |\n|---------------------------------------------|------------------|-------------------------------|\n| [deleteCustomField()](#deleteCustomField()) | `void` | Deletes this field. |\n| [getValue()](#getValue()) | `Object` | Gets the value of the field. |\n| [setLabel(field)](#setLabel(ExtendedField)) | [CustomField](#) | Sets the label of this field. |\n| [setValue(value)](#setValue(Object)) | [CustomField](#) | Sets the value of this field. |\n\nDetailed documentation\n----------------------\n\n### `get``Label()`\n\nGets the label for this field. This may be a Field, ExtendedField, or a String.\n\n```javascript\n// Logs the label for all the address fields associated with contact\n// 'John Doe'. This method can be similarly called for any field that has\n// a label.\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst addressFields = contacts[0].getAddresses();\nfor (let i = 0; i \u003c addressFields.length; i++) {\n Logger.log(addressFields[i].getLabel());\n}\n```\n\n#### Return\n\n\n`Object` --- the label for this field\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n### `set``Label(label)`\n\nSets the label of this field.\n\n```javascript\n// Sets the label to 'Apartment' for the first address field associated\n// with contact 'John Doe'. This method can be similarly called for any\n// field that has a label.\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst addressFields = contacts[0].getAddresses();\naddressFields[0].setLabel('Apartment');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|----------|------------------------------|\n| `label` | `String` | the new label for this field |\n\n#### Return\n\n\n[CustomField](#) --- this field, useful for chaining\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\nDeprecated methods\n------------------\n\n### `delete``Custom``Field()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nDeletes this field.\n\n```javascript\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst fields = contacts[0].getCustomFields();\nfor (let i = 0; i \u003c fields.length; i++) {\n if (fields[i].getLabel() === 'foo') {\n fields[i].deleteCustomField();\n }\n}\n```\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n### `get``Value()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nGets the value of the field.\n\n```javascript\n// Logs the value of all the custom fields for contact 'John Doe'\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst fields = contacts[0].getCustomFields();\nfor (const i in fields) {\n Logger.log(fields[i].getValue());\n}\n```\n\n#### Return\n\n\n`Object` --- the value stored in the field\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n### `set``Label(field)`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nSets the label of this field.\n\n```javascript\n// Sets the first custom field associated with contact 'John Doe' to use 'Mail\n// application' as a label, with 'Gmail' as the value.\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst field = contacts[0].getCustomFields()[0];\nfield.setLabel('Mail application');\nfield.setValue('Gmail');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|-----------------------------------------------------------------|------------------------|\n| `field` | [ExtendedField](/apps-script/reference/contacts/extended-field) | the new standard label |\n\n#### Return\n\n\n[CustomField](#) --- this field, useful for chaining\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n### `set``Value(value)`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nSets the value of this field.\n\n```javascript\n// Sets the first custom field associated with contact 'John Doe' to use 'Mail\n// application' as a label, with 'Gmail' as the value.\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst field = contacts[0].getCustomFields()[0];\nfield.setLabel('Mail application');\nfield.setValue('Gmail');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|----------|---------------|\n| `value` | `Object` | the new value |\n\n#### Return\n\n\n[CustomField](#) --- this field, useful for chaining\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`"]]