Google Apps Script

Class CustomField

A custom field in a Contact.

Methods

MethodReturn typeBrief description
deleteCustomField()voidDeletes this field.
getLabel()ObjectGets the label for this field.
getValue()ObjectGets the value of the field.
setLabel(field)CustomFieldSets the label of this field.
setLabel(label)CustomFieldSets the label of this field.
setValue(value)CustomFieldSets the value of this field.

Detailed documentation

deleteCustomField()

Deletes this field.

 
var contacts = ContactsApp.getContactsByName('John Doe');
 var fields = contacts[0].getCustomFields();
 for (var i = 0; i < fields.length; i++) {
   if (fields[i].getLabel() == 'foo') {
     fields[i].deleteCustomField();
   }
 }
 

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


getValue()

Gets the value of the field.

 
// Logs the value of all the custom fields for contact 'John Doe'
 var contacts = ContactsApp.getContactsByName('John Doe');
 var fields = contacts[0].getCustomFields();
 for (var i in fields) {
   Logger.log(fields[i].getValue());
 }
 

Return

Object — the value stored in the field


setLabel(field)

Sets the label of this field.

 
// Sets the first custom field associated with contact 'John Doe' to use 'Mail application' as
 // a label, with 'Gmail' as the value.
 var contacts = ContactsApp.getContactsByName('John Doe');
 var field = contacts[0].getCustomFields()[0];
 field.setLabel('Mail application');
 field.setValue('Gmail');
 

Parameters

NameTypeDescription
fieldExtendedFieldthe new standard label

Return

CustomField — this field, useful 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

CustomField — this field, useful for chaining


setValue(value)

Sets the value of this field.

 
// Sets the first custom field associated with contact 'John Doe' to use 'Mail application' as
 // a label, with 'Gmail' as the value.
 var contacts = ContactsApp.getContactsByName('John Doe');
 var field = contacts[0].getCustomFields()[0];
 field.setLabel('Mail application');
 field.setValue('Gmail');
 

Parameters

NameTypeDescription
valueObjectthe new value

Return

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