// 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());
}
// 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');
// Deletes all the dates that are set for contact 'John Doe'
var contacts = ContactsApp.getContactsByName('John Doe');
var dates = contacts[0].getDates();
for (var i = 0; i < dates.length; i++) {
dates[i].deleteDateField();
}
注: 標準の JavaScript Date オブジェクトの場合、getDay() メソッドは曜日を返します。
// Logs the day of the birthday for contact 'John Doe'
var contacts = ContactsApp.getContactsByName('John Doe');
var birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
Logger.log(birthday.getDay());
// Logs the month of the birthday for contact 'John Doe'
var contacts = ContactsApp.getContactsByName('John Doe');
var birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
Logger.log(birthday.getMonth());
// Logs the year of the birthday for contact 'John Doe'
var contacts = ContactsApp.getContactsByName('John Doe');
var birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
Logger.log(birthday.getYear());
// Sets the birthday for contact 'John Doe' to April 1
var contacts = ContactsApp.getContactsByName('John Doe');
var birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
birthday.setDate(ContactsApp.Month.APRIL, 1);
// Sets the birthday for contact 'John Doe' to April 1, 1980
var contacts = ContactsApp.getContactsByName('John Doe');
var birthday = contacts[0].getDates(ContactsApp.Field.BIRTHDAY)[0];
birthday.setDate(ContactsApp.Month.APRIL, 1, 1980);
// Retrieves the first date that's set for contact 'John Doe' and re-labels
// it as an anniversary
var contacts = ContactsApp.getContactsByName('John Doe');
var firstDate = contacts[0].getDates()[0];
firstDate.setLabel(ContactsApp.Field.ANNIVERSARY);