Google Apps Script

Class EmailField

An email field in a Contact.

Methods

MethodReturn typeBrief description
deleteEmailField()voidDeletes this email address from the Contact.
getAddress()StringGet the address for this field.
getDisplayName()StringReturns the display name for this email address.
getLabel()ObjectGets the label for this field.
isPrimary()BooleanGets whether this is the primary field value.
setAddress(address)EmailFieldSets the address of this field.
setAsPrimary()EmailFieldSets this field to primary.
setDisplayName(name)EmailFieldSets the display name for this email address.
setLabel(field)EmailFieldSets the label of this field.
setLabel(label)EmailFieldSets the label of this field.

Detailed documentation

deleteEmailField()

Deletes this email address from the Contact.

 
// Retrieves and deletes the work email address for contact 'John Doe'
 var contacts = ContactsApp.getContactsByName('John Doe');
 var workEmail = contacts[0].getEmails(ContactsApp.Field.WORK_EMAIL);
 workEmail[0].deleteEmailField();
 

getAddress()

Get the address for this field.

 
// Logs the address for the 'Home Address' field for contact 'John Doe'.
 // Can be used similarly for other fields that contain addresses.
 var contacts = ContactsApp.getContactsByName('John Doe');
 var homeAddress = contacts[0].getAddresses(ContactsApp.Field.HOME_ADDRESS);
 Logger.log(homeAddress[0].getAddress());
 

Return

String — the address as a string


getDisplayName()

Returns the display name for this email address.

 
// Logs the display name for the the work email address for contact 'John Doe'
 var contacts = ContactsApp.getContactsByName('John Doe');
 var workEmail = contacts[0].getEmails(ContactsApp.Field.WORK_EMAIL);
 Logger.log(workEmail[0].getDisplayName());
 

Return

String — the display name for this email


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.
 var contacts = ContactsApp.getContactsByName('John Doe');
 var addressFields = contacts[0].getAddresses();
 for (var i = 0; i < addressFields.length; i++) {
   Logger.log(addressFields[i].getLabel());
 }
 

Return

Object — the label for this field


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.
 var contacts = ContactsApp.getContactsByName('John Doe');
 var addressFields = contacts[0].getAddresses();
 Logger.log(addressFields[0].isPrimary());
 

Return

Boolean — whether this is primary


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.
 var contacts = ContactsApp.getContactsByName('John Doe');
 var homeAddress = contacts[0].getAddresses(ContactsApp.Field.HOME_ADDRESS);
 homeAddress[0].setAddress('123 Main St, Raleigh, NC, 27601');
 

Parameters

NameTypeDescription
addressStringthe new address

Return

EmailField — this field, useful for chaining


setAsPrimary()

Sets this field to primary.

 
// Sets the the first address field associated with contact 'John Doe'
 // as primary. This method can be similarly called for any field.
 var contacts = ContactsApp.getContactsByName('John Doe');
 var addressFields = contacts[0].getAddresses();
 addressFields[0].setAsPrimary();
 

Return

EmailField — this FieldValue for chaining


setDisplayName(name)

Sets the display name for this email address.

 
// Sets the display name to 'Doe, John' for the the work email address for contact 'John Doe'
 var contacts = ContactsApp.getContactsByName('John Doe');
 var workEmail = contacts[0].getEmails(ContactsApp.Field.WORK_EMAIL);
 workEmail[0].setDisplayName('Doe, John');
 

Parameters

NameTypeDescription
nameStringthe new display name for this email address

Return

EmailField — this email field, useful for chaining


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.
 var contacts = ContactsApp.getContactsByName('John Doe');
 var addressFields = contacts[0].getAddresses();
 addressFields[0].setLabel(ContactsApp.Field.WORK_ADDRESS);
 

Parameters

NameTypeDescription
fieldFieldthe new standard label

Return

EmailField — this FieldValue for chaining


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.
 var contacts = ContactsApp.getContactsByName('John Doe');
 var addressFields = contacts[0].getAddresses();
 addressFields[0].setLabel('Apartment');
 

Parameters

NameTypeDescription
labelStringthe new label for this field

Return

EmailField — this field, useful for chaining

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.