Google-calendar – Add contacts to “where” field in Google Calendar entry

google-calendargoogle-contacts

Say I have an event that takes place at one of my contact's, I'd like to add this contact to the "where" field of the event, so that e.g. Google Maps can display the appropriate address. Is this possible?

Note: The contact doesn't use Google apps at all, so adding him/her as a participant of the meeting is not an option.

Best Answer

I wrote a small snippet that does the trick.

Code

function CalendarEvents() {
  // get contact 
  var contactByMail = ContactsApp
    .getContactsByEmailAddress('e-mail with address in Google Contacts');

  // get location
  var location = contactByMail[0].getAddresses()[0].getAddress();

  // set date
  var date = new Date("September 26, 2013");

  // fetch calendar
  var cal = CalendarApp.getCalendarById('e-mail of your calendar')
    .createAllDayEvent("test", date, {location:location});
}

Usage

This code will run just from within the script. There's no need to add it to a Google Spreadsheet. Go to script.google.com while you're logged in. Add the code and press the bug button to authenticate the script. Afterwards, press the play button to execute the script.

References

See the ContactsApp and the CalendarApp from Google Apps Script.

  1. CalendarApp
  2. ContactsApp