I need to import a list of last and first names from contacts into google sheets

71 Views Asked by At

I'm pretty new at google app script, I've found the following script that will get me a list of contacts but it includes "other contacts" and I want to only grab the group "My Contacts" and list them last name and first name in two columns. I've been trying to figure that out but I'm at a loss.

function importFullName() {
  
  var contacts = ContactApp.getContactGroup('My Contacts').getContacts(), output = [];  
  for(var i = 0, iLen = contacts.length; i < iLen; i++) {
    var fullname = contacts[i].getFullName();    
    if(fullname) {
      output.push([fullname]);
    } else {
      continue;
    }
  }  
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Contacts list").getRange(1, 1, output.length, 1).setValues(output);
}

This script works if I use ContactsApp.getContacts(), but doesn't once I change to getContactsGroup it stops working

0

There are 0 best solutions below