Class PhoneField
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Detaillierte Dokumentation
getLabel()
Ruft das Label für dieses Feld ab. Dies kann ein Feld, ein erweitertes Feld oder ein String sein.
// 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());
}
Rückflug
Object
– das Label für dieses Feld
Autorisierung
Scripts, die diese Methode verwenden, erfordern eine Autorisierung für einen oder mehrere der folgenden Bereiche:
-
https://www.google.com/m8/feeds
isPrimary()
Gibt an, ob dies der Wert des Hauptfelds ist.
// Logs whether or not the first address field associated with contact
// 'John Doe' is labeled as primary. This method can be similarly called
// for any field.
const contacts = ContactsApp.getContactsByName('John Doe');
const addressFields = contacts[0].getAddresses();
Logger.log(addressFields[0].isPrimary());
Rückflug
Boolean
– ob es sich um die primäre Adresse handelt
Autorisierung
Scripts, die diese Methode verwenden, erfordern eine Autorisierung für einen oder mehrere der folgenden Bereiche:
-
https://www.google.com/m8/feeds
setAsPrimary()
Legt dieses Feld als primär fest.
// Sets the first address field associated with contact 'John Doe'
// as primary. This method can be similarly called for any field.
const contacts = ContactsApp.getContactsByName('John Doe');
const addressFields = contacts[0].getAddresses();
addressFields[0].setAsPrimary();
Rückflug
PhoneField
– diese FieldValue für die Verkettung
Autorisierung
Scripts, die diese Methode verwenden, erfordern eine Autorisierung für einen oder mehrere der folgenden Bereiche:
-
https://www.google.com/m8/feeds
setLabel(field)
Legt das Label dieses Felds fest.
// Sets the label to 'Work' 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(ContactsApp.Field.WORK_ADDRESS);
Parameter
Name | Typ | Beschreibung |
field | Field
| das neue Standardlabel |
Rückflug
PhoneField
– diese FieldValue für die Verkettung
Autorisierung
Scripts, die diese Methode verwenden, erfordern eine Autorisierung für einen oder mehrere der folgenden Bereiche:
-
https://www.google.com/m8/feeds
setLabel(label)
Legt das Label dieses Felds fest.
// 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');
Parameter
Name | Typ | Beschreibung |
label | String | das neue Label für dieses Feld |
Rückflug
PhoneField
– dieses Feld ist für die Verkettung nützlich
Autorisierung
Scripts, die diese Methode verwenden, erfordern eine Autorisierung für einen oder mehrere der folgenden Bereiche:
-
https://www.google.com/m8/feeds
Eingestellte Methoden
deletePhoneField()
Veraltet. Diese Funktion wurde eingestellt und sollte in neuen Scripts nicht verwendet werden.
Löscht dieses Feld für die Telefonnummer.
// Retrieves and deletes the work phone number field for contact 'John
// Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const phoneFields = contacts[0].getPhones(ContactsApp.Field.WORK_PHONE);
phoneFields[0].deletePhoneField();
Autorisierung
Scripts, die diese Methode verwenden, erfordern eine Autorisierung für einen oder mehrere der folgenden Bereiche:
-
https://www.google.com/m8/feeds
getPhoneNumber()
Veraltet. Diese Funktion wurde eingestellt und sollte in neuen Scripts nicht verwendet werden.
Telefonnummer für dieses Feld abrufen
// Logs the work phone number for contact 'John Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const phoneFields = contacts[0].getPhones(ContactsApp.Field.WORK_PHONE);
Logger.log(phoneFields[0].getPhoneNumber());
Rückflug
String
– die Zahl als String
Autorisierung
Scripts, die diese Methode verwenden, erfordern eine Autorisierung für einen oder mehrere der folgenden Bereiche:
-
https://www.google.com/m8/feeds
setPhoneNumber(number)
Veraltet. Diese Funktion wurde eingestellt und sollte in neuen Scripts nicht verwendet werden.
Legt die Telefonnummer für dieses Feld fest.
// Sets the work phone number for contact 'John Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const phoneFields = contacts[0].getPhones(ContactsApp.Field.WORK_PHONE);
phoneFields[0].setPhoneNumber('212-555-1234');
Parameter
Name | Typ | Beschreibung |
number | String | die neue Nummer |
Rückflug
PhoneField
– dieses Feld ist für die Verkettung nützlich
Autorisierung
Scripts, die diese Methode verwenden, erfordern eine Autorisierung für einen oder mehrere der folgenden Bereiche:
-
https://www.google.com/m8/feeds
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
Zuletzt aktualisiert: 2025-07-26 (UTC).
[null,null,["Zuletzt aktualisiert: 2025-07-26 (UTC)."],[[["\u003cp\u003e\u003ccode\u003ePhoneField\u003c/code\u003e is deprecated and the People API advanced service should be used instead.\u003c/p\u003e\n"],["\u003cp\u003eIt represents a phone number field within a Contact and provides methods for getting and setting labels, and determining if it's the primary number.\u003c/p\u003e\n"],["\u003cp\u003eAlthough deprecated, methods like \u003ccode\u003edeletePhoneField()\u003c/code\u003e, \u003ccode\u003egetPhoneNumber()\u003c/code\u003e, and \u003ccode\u003esetPhoneNumber()\u003c/code\u003e are still documented but shouldn't be used in new scripts.\u003c/p\u003e\n"],["\u003cp\u003eAll methods require authorization with the \u003ccode\u003ehttps://www.google.com/m8/feeds\u003c/code\u003e scope.\u003c/p\u003e\n"]]],["The `PhoneField` is deprecated in favor of the People API. It represents a phone number within a contact. Key actions include setting or getting a field's label, determining if a field is primary, and setting a field as primary. Deprecated methods include deleting a phone field, getting a phone number, and setting a phone number. Scripts require authorization with `https://www.google.com/m8/feeds` scope. Using the methods you can modify contacts labels, or set them as primary.\n"],null,["# Class PhoneField\n\nPhoneField\n\n\n**Deprecated.** Instead, use the [People API advanced\nservice](/apps-script/advanced/people)\n\nA phone number 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| [isPrimary()](#isPrimary()) | `Boolean` | Gets whether this is the primary field value. |\n| [setAsPrimary()](#setAsPrimary()) | [PhoneField](#) | Sets this field to primary. |\n| [setLabel(field)](#setLabel(Field)) | [PhoneField](#) | Sets the label of this field. |\n| [setLabel(label)](#setLabel(String)) | [PhoneField](#) | Sets the label of this field. |\n\n### Deprecated methods\n\n| Method | Return type | Brief description |\n|---------------------------------------------------|-----------------|---------------------------------------|\n| [deletePhoneField()](#deletePhoneField()) | `void` | Deletes this phone number field. |\n| [getPhoneNumber()](#getPhoneNumber()) | `String` | Get the phone number for this field. |\n| [setPhoneNumber(number)](#setPhoneNumber(String)) | [PhoneField](#) | Sets the phone number for 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### `is``Primary()`\n\nGets whether this is the primary field value.\n\n```javascript\n// Logs whether or not the first address field associated with contact\n// 'John Doe' is labeled as primary. This method can be similarly called\n// for any field.\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst addressFields = contacts[0].getAddresses();\nLogger.log(addressFields[0].isPrimary());\n```\n\n#### Return\n\n\n`Boolean` --- whether this is primary\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``As``Primary()`\n\nSets this field to primary.\n\n```javascript\n// Sets the first address field associated with contact 'John Doe'\n// as primary. This method can be similarly called for any field.\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst addressFields = contacts[0].getAddresses();\naddressFields[0].setAsPrimary();\n```\n\n#### Return\n\n\n[PhoneField](#) --- this FieldValue 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``Label(field)`\n\nSets the label of this field.\n\n```javascript\n// Sets the label to 'Work' 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(ContactsApp.Field.WORK_ADDRESS);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|------------------------------------------------|------------------------|\n| `field` | [Field](/apps-script/reference/contacts/field) | the new standard label |\n\n#### Return\n\n\n[PhoneField](#) --- this FieldValue 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``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[PhoneField](#) --- 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``Phone``Field()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nDeletes this phone number field.\n\n```javascript\n// Retrieves and deletes the work phone number field for contact 'John\n// Doe'\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst phoneFields = contacts[0].getPhones(ContactsApp.Field.WORK_PHONE);\nphoneFields[0].deletePhoneField();\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``Phone``Number()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nGet the phone number for this field.\n\n```javascript\n// Logs the work phone number for contact 'John Doe'\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst phoneFields = contacts[0].getPhones(ContactsApp.Field.WORK_PHONE);\nLogger.log(phoneFields[0].getPhoneNumber());\n```\n\n#### Return\n\n\n`String` --- the number as a string\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``Phone``Number(number)`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nSets the phone number for this field.\n\n```javascript\n// Sets the work phone number for contact 'John Doe'\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst phoneFields = contacts[0].getPhones(ContactsApp.Field.WORK_PHONE);\nphoneFields[0].setPhoneNumber('212-555-1234');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|----------|----------|----------------|\n| `number` | `String` | the new number |\n\n#### Return\n\n\n[PhoneField](#) --- 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`"]]