Say I have 5 contacts in a group. I would like to see all their details in one page (/view), preferably separated by an horizontal line between every contact.

Is something like this possible?

  • Can you give me some feedback, whether my answer was sufficient? – Jacob Jan Tuinstra Jan 25 '13 at 20:34

The following Google Apps Script will enable you to select a particular group (available in your contacts) and present all contacts. The data shown, only contains the full name and e-mail addresses (if available). You can add other data if you wish (yourself...):

function doGet(e) {
  var app = UiApp.createApplication().setTitle('Group Contacts');

  // create grid
  var mFlex = app.createFlexTable().setId('mFlex').setStyleAttribute('borderCollapse','collapse');

  // create label for title
  mFlex.setWidget(0, 0, app.createLabel('Display Contacts per Group').setStyleAttribute('fontWeight', 'bold'));

  // retrieve group names
  var gNames = ContactsApp.getContactGroups();

  // create listbox to hold group names
  mFlex.setWidget(1, 0, app.createListBox().setId('lBox').setName('lBox')

  // add groups to listbox
  app.getElementById('lBox').addItem('Select Contact Group ...');
  for(var i in gNames) {

  // set first item in lBox
  app.getElementById('lBox').setItemSelected(0, true);

  // all to app

  //return to appliccation
  return app; 

function getContacts(e) {
  // get active application
  var app = UiApp.getActiveApplication();

  // create panel
  var fTable = app.createFlexTable().setId('fTable');
  var vPanel = app.createVerticalPanel().setId('vPanel').setWidth(500);
  var sPanel = app.createScrollPanel().setId('sPanel').setHeight(300).setWidth(520);

   // get group name
  var gName = ContactsApp.getContactGroup(e.parameter.lBox);

  // get group contacts
  var gContacts = ContactsApp.getContactsByGroup(gName);

  // itterate through contacts 
  if(gContacts.length == 0) {
    fTable.setWidget(0, 0, app.createLabel('No contacts available'));
  } else { 
    // add headers
     app.getElementById('fTable').setWidget(0, 0, app.createLabel('Full name')
       .setStyleAttribute('fontWeight', 'bold'));
     app.getElementById('fTable').setWidget(0, 1, app.createLabel('e-mail address')
       .setStyleAttribute('fontWeight', 'bold'));

    // add data to fTable    
    for(var i=0, len=gContacts.length; i<len; i++) {
      if(gContacts[i].getFullName() == null) {
        app.getElementById('fTable').setWidget(parseInt(i)+1, 0, app.createLabel('No name').setWidth(200)
          .setStyleAttribute('borderBottom','1px solid #e1e1e1'));
      } else {
        app.getElementById('fTable').setWidget(parseInt(i)+1, 0, app.createLabel(gContacts[i].getFullName()).setWidth(200)
          .setStyleAttribute('borderBottom','1px solid #e1e1e1'));
      if(gContacts[i].getEmails().length == 0) {
        app.getElementById('fTable').setWidget(parseInt(i)+1, 1, app.createLabel('No e-mail address').setWidth(200)
          .setStyleAttribute('borderBottom','1px solid #e1e1e1'));
      } else {        
        app.getElementById('fTable').setWidget(parseInt(i)+1, 1, app.createLabel(gContacts[i].getEmails()[0].getAddress())
        .setWidth(300).setStyleAttribute('borderBottom','1px solid #e1e1e1'));    

  // add widgets
  app.getElementById('mFlex').setWidget(2, 0, sPanel.add(vPanel.add(fTable)));

  //return to application
  return app;

Upon install, press the bug to gain authorization:

enter image description here

Here's how it looks like in action:

contacts per group

  • When I try to deploy the code at script.google.com I get an error: "Authorization is required to perform that action". – Eyal Levin Feb 28 '13 at 8:28
  • @eyalev see revised answer. – Jacob Jan Tuinstra Mar 1 '13 at 7:09

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.