// Logs the address for the 'Home Address' field for contact 'John Doe'.// Can be used similarly for other fields that contain addresses.constcontacts=ContactsApp.getContactsByName('John Doe');consthomeAddress=contacts[0].getAddresses(ContactsApp.Field.HOME_ADDRESS);Logger.log(homeAddress[0].getAddress());
Return
String — the address as a string
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.google.com/m8/feeds
getLabel()
Gets the label for this field. This may be a Field, ExtendedField, or a 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.constcontacts=ContactsApp.getContactsByName('John Doe');constaddressFields=contacts[0].getAddresses();for(leti=0;i < addressFields.length;i++){Logger.log(addressFields[i].getLabel());}
Return
Object — the label for this field
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.google.com/m8/feeds
isPrimary()
Gets whether this is the primary field value.
// 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.constcontacts=ContactsApp.getContactsByName('John Doe');constaddressFields=contacts[0].getAddresses();Logger.log(addressFields[0].isPrimary());
Return
Boolean — whether this is primary
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.google.com/m8/feeds
setAddress(address)
Sets the address of this field.
// Sets the address for the 'Home Address' field for contact 'John Doe'.// Can be used similarly for other fields that contain addresses.constcontacts=ContactsApp.getContactsByName('John Doe');consthomeAddress=contacts[0].getAddresses(ContactsApp.Field.HOME_ADDRESS);homeAddress[0].setAddress('123 Main St, Raleigh, NC, 27601');
Scripts that use this method require authorization with one or more of the following scopes:
https://www.google.com/m8/feeds
setAsPrimary()
Sets this field to primary.
// Sets the first address field associated with contact 'John Doe'// as primary. This method can be similarly called for any field.constcontacts=ContactsApp.getContactsByName('John Doe');constaddressFields=contacts[0].getAddresses();addressFields[0].setAsPrimary();
Scripts that use this method require authorization with one or more of the following scopes:
https://www.google.com/m8/feeds
setLabel(field)
Sets the label of this field.
// 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.constcontacts=ContactsApp.getContactsByName('John Doe');constaddressFields=contacts[0].getAddresses();addressFields[0].setLabel(ContactsApp.Field.WORK_ADDRESS);
Scripts that use this method require authorization with one or more of the following scopes:
https://www.google.com/m8/feeds
setLabel(label)
Sets the label of this field.
// 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.constcontacts=ContactsApp.getContactsByName('John Doe');constaddressFields=contacts[0].getAddresses();addressFields[0].setLabel('Apartment');
Scripts that use this method require authorization with one or more of the following scopes:
https://www.google.com/m8/feeds
Deprecated methods
deleteAddressField()
Deprecated. This function is deprecated and should not be used in new scripts.
Deletes this address field.
// The code below deletes the home addresses for a contact named "John Doe"constcontacts=ContactsApp.getContactsByName('John Doe');consthomeAddresses=contacts[0].getAddresses(ContactsApp.Field.HOME_ADDRESS);for(constiinhomeAddresses){homeAddresses[i].deleteAddressField();}
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-02 UTC."],[[["\u003cp\u003e\u003ccode\u003eAddressField\u003c/code\u003e is deprecated; use the People API advanced service instead.\u003c/p\u003e\n"],["\u003cp\u003eIt represents an address field in a contact and provides methods for getting, setting, and modifying address information.\u003c/p\u003e\n"],["\u003cp\u003eMethods include \u003ccode\u003egetAddress()\u003c/code\u003e, \u003ccode\u003esetLabel()\u003c/code\u003e, \u003ccode\u003eisPrimary()\u003c/code\u003e, \u003ccode\u003esetAddress()\u003c/code\u003e, \u003ccode\u003esetAsPrimary()\u003c/code\u003e, and the deprecated \u003ccode\u003edeleteAddressField()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eEach method has specific functionalities, such as retrieving the address, setting it as primary, or deleting the field, along with authorization requirements.\u003c/p\u003e\n"]]],["The `AddressField` in a contact, now deprecated in favor of the People API, manages a contact's address information. Key actions include: retrieving the address string via `getAddress()`, accessing the field's label using `getLabel()`, and checking if it's the primary address with `isPrimary()`. Users can set a new address with `setAddress(address)`, designate it as the primary address with `setAsPrimary()`, or modify the label with `setLabel(field)` or `setLabel(label)`. `deleteAddressField()` has been deprecated. These methods require specific authorization scopes.\n"],null,["AddressField\n\n\n**Deprecated.** Instead, use the [People API advanced\nservice](/apps-script/advanced/people)\n\nAddress field in a contact. \n\nMethods\n\n| Method | Return type | Brief description |\n|--------------------------------------------|-------------------|-----------------------------------------------|\n| [getAddress()](#getAddress()) | `String` | Get the address for this field. |\n| [getLabel()](#getLabel()) | `Object` | Gets the label for this field. |\n| [isPrimary()](#isPrimary()) | `Boolean` | Gets whether this is the primary field value. |\n| [setAddress(address)](#setAddress(String)) | [AddressField](#) | Sets the address of this field. |\n| [setAsPrimary()](#setAsPrimary()) | [AddressField](#) | Sets this field to primary. |\n| [setLabel(field)](#setLabel(Field)) | [AddressField](#) | Sets the label of this field. |\n| [setLabel(label)](#setLabel(String)) | [AddressField](#) | Sets the label of this field. |\n\nDeprecated methods\n\n| Method | Return type | Brief description |\n|-----------------------------------------------|-------------|-----------------------------|\n| [deleteAddressField()](#deleteAddressField()) | `void` | Deletes this address field. |\n\nDetailed documentation \n\n`get``Address()` \nGet the address for this field.\n\n```javascript\n// Logs the address for the 'Home Address' field for contact 'John Doe'.\n// Can be used similarly for other fields that contain addresses.\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst homeAddress = contacts[0].getAddresses(ContactsApp.Field.HOME_ADDRESS);\nLogger.log(homeAddress[0].getAddress());\n```\n\nReturn\n\n\n`String` --- the address as a string\n\nAuthorization\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``Label()` \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\nReturn\n\n\n`Object` --- the label for this field\n\nAuthorization\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()` \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\nReturn\n\n\n`Boolean` --- whether this is primary\n\nAuthorization\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``Address(address)` \nSets the address of this field.\n\n```javascript\n// Sets the address for the 'Home Address' field for contact 'John Doe'.\n// Can be used similarly for other fields that contain addresses.\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst homeAddress = contacts[0].getAddresses(ContactsApp.Field.HOME_ADDRESS);\nhomeAddress[0].setAddress('123 Main St, Raleigh, NC, 27601');\n```\n\nParameters\n\n| Name | Type | Description |\n|-----------|----------|-----------------|\n| `address` | `String` | the new address |\n\nReturn\n\n\n[AddressField](#) --- this field, useful for chaining\n\nAuthorization\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()` \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\nReturn\n\n\n[AddressField](#) --- this FieldValue for chaining\n\nAuthorization\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)` \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\nParameters\n\n| Name | Type | Description |\n|---------|------------------------------------------------|------------------------|\n| `field` | [Field](/apps-script/reference/contacts/field) | the new standard label |\n\nReturn\n\n\n[AddressField](#) --- this FieldValue for chaining\n\nAuthorization\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)` \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\nParameters\n\n| Name | Type | Description |\n|---------|----------|------------------------------|\n| `label` | `String` | the new label for this field |\n\nReturn\n\n\n[AddressField](#) --- this field, useful for chaining\n\nAuthorization\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`delete``Address``Field()` \n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nDeletes this address field.\n\n```javascript\n// The code below deletes the home addresses for a contact named \"John Doe\"\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst homeAddresses = contacts[0].getAddresses(ContactsApp.Field.HOME_ADDRESS);\nfor (const i in homeAddresses) {\n homeAddresses[i].deleteAddressField();\n}\n```\n\nAuthorization\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`"]]