3

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.

  • As opposed to putting their address you mean? – Eight Days of Malaise Mar 3 '11 at 1:02
  • Well, actually what I want is their address (because that's the place), but the rational for specifying the contact would be "I'm at X's place). The calendar could use X's address, then. – jhwist Mar 3 '11 at 7:01
  • @jhwist: did you find my answer useful? Please give feedback if you need assistance with the implementation. – Jacob Jan Tuinstra Dec 22 '12 at 0:15
2

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
| improve this answer | |
  • 1
    Asking as a newbie: How exactly can I use this? Where do I have to paste the code? – David Sep 25 '13 at 20:21
  • 1
    @David Moin, see my revised answer. Thanks for your feedback !! – Jacob Jan Tuinstra Sep 26 '13 at 7:15
  • When I try to debug the script I get the following Error: TypeError: Cannot call method "getAddresses" of undefined. (line 7, file "Code") What do I miss? – David Sep 30 '13 at 10:11
  • @David have you added an address of the e-mail contact? – Jacob Jan Tuinstra Sep 30 '13 at 10:25
  • 1
    But I don't see the use in navigating to the script and entering the mail address everytime. That's not much better than navigating to contacts.google.com and copying the address from there. I thought of a solution where you could simply do this from the event page. – David Sep 30 '13 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.