Google Apps Script

Class PhoneField

A phone number field in a Contact.

Methods

MethodReturn typeBrief description
deletePhoneField()voidDeletes this phone number field.
getLabel()ObjectGets the label for this field.
getPhoneNumber()StringGet the phone number for this field.
isPrimary()BooleanGets whether this is the primary field value.
setAsPrimary()PhoneFieldSets this field to primary.
setLabel(field)PhoneFieldSets the label of this field.
setLabel(label)PhoneFieldSets the label of this field.
setPhoneNumber(number)PhoneFieldSets the phone number for this field.

Detailed documentation

deletePhoneField()

Deletes this phone number field.

 
// Retrieves and deletes the work phone number field for contact 'John
 // Doe'
 var contacts = ContactsApp.getContactsByName('John Doe');
 var phoneFields = contacts[0].getPhones(ContactsApp.Field.WORK_PHONE);
 phoneFields[0].deletePhoneField();
 

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


getPhoneNumber()

Get the phone number for this field.

 
// Logs the work phone number for contact 'John Doe'
 var contacts = ContactsApp.getContactsByName('John Doe');
 var phoneFields = contacts[0].getPhones(ContactsApp.Field.WORK_PHONE);
 Logger.log(phoneFields[0].getPhoneNumber());
 

Return

String — the number as a string


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


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

PhoneField — this FieldValue 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

PhoneField — 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

PhoneField — this field, useful for chaining


setPhoneNumber(number)

Sets the phone number for this field.

 
// Sets the work phone number for contact 'John Doe'
 var contacts = ContactsApp.getContactsByName('John Doe');
 var phoneFields = contacts[0].getPhones(ContactsApp.Field.WORK_PHONE);
 phoneFields[0].setPhoneNumber('212-555-1234');
 

Parameters

NameTypeDescription
numberStringthe new number

Return

PhoneField — 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.