A ContactGroup is is a group of contacts.
Methods
| Method | Return type | Brief description |
|---|---|---|
addContact(contact) | ContactGroup | Adds the given contact to this group |
deleteGroup() | void | Deletes this contact group. |
getContacts() | Contact[] | Gets all the contacts in this contact group. |
getId() | String | Gets the id of this contact group. |
getName() | String | Gets the name of this contact group. |
isSystemGroup() | Boolean | Gets a boolean value to determine whether this contact group is a system group (undeletable) or not. |
removeContact(contact) | ContactGroup | Removes the given contact from this group |
setName(name) | ContactGroup | Sets the name of this contact group. |
Detailed documentation
addContact(contact)
Adds the given contact to this group
// The code below creates a new contact and adds it to the "Work Friends" contact group
var contact = ContactsApp.createContact('John', 'Doe', 'john.doe@example.com');
var group = ContactsApp.getContactGroup('Work Friends');
group.addContact(contact);
Parameters
| Name | Type | Description |
|---|---|---|
contact | Contact | the contact to be added to the group |
Return
ContactGroup — this contact group
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://www.google.com/m8/feeds
See also
deleteGroup()
Deletes this contact group.
Deletes non-system groups only; system groups cannot be deleted.
// The code below retrieves a contact group named "Work Friends" and deletes it
var group = ContactsApp.getContactGroup('Work Friends');
group.deleteGroup();
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://www.google.com/m8/feeds
See also
getContacts()
Gets all the contacts in this contact group.
// The code below retrieves all the contacts in the group named "Work Friends"
var group = ContactsApp.getContactGroup('Work Friends');
var contacts = group.getContacts();
Return
Contact[] — the contacts in this group
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://www.google.com/m8/feeds
getId()
Gets the id of this contact group.
// The code below retrieves a contact group named "Work Friends" and gets its id
var group = ContactsApp.getContactGroup('Work Friends');
var id = group.getId();
Return
String — the id of this group
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://www.google.com/m8/feeds
getName()
Gets the name of this contact group.
// The code below creates a new contact group and then retrieves its name
var group = ContactsApp.createContactGroup('Work Friends');
var name = group.getName();
Return
String — this name of this contact group
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://www.google.com/m8/feeds
See also
isSystemGroup()
Gets a boolean value to determine whether this contact group is a system group (undeletable) or not.
Systems groups are a set of groups that are predefined in Google Contacts, such as "My Contacts", "Family", "Coworkers", etc. The name of a system group usually contains the words "System Group".
// The code below retrieves two contact groups, then logs whether or not
// each is a system group.
var myGroup = ContactsApp.getContactGroup('Work Friends');
var systemGroup = ContactsApp.getContactGroup('System Group: Coworkers');
Logger.log(myGroup.isSystemGroup()); // Returns false, if the group exists.
Logger.log(systemGroup.isSystemGroup()); // Returns true.
Return
Boolean — whether or not this contact group is a system group
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://www.google.com/m8/feeds
removeContact(contact)
Removes the given contact from this group
// The code below retrieves all the contacts named "John Doe' and removes them from the
// "Work Friends" contact group
var contacts = ContactsApp.getContactsByName('John Doe');
var group = ContactsApp.getContactGroup('Work Friends');
for (var i in contacts) {
group.removeContact(contacts[i]);
}
Parameters
| Name | Type | Description |
|---|---|---|
contact | Contact | the contact to be removed from the group |
Return
ContactGroup — this contact group
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://www.google.com/m8/feeds
See also
setName(name)
Sets the name of this contact group.
// The code below retrieves the contact group named "Work Friends" and renames it to
// "Work Buddies"
var group = ContactsApp.getContactGroup('Work Friends');
group.setName('Work Buddies');
Parameters
| Name | Type | Description |
|---|---|---|
name | String | the new name for the contact group |
Return
ContactGroup — this contact group
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://www.google.com/m8/feeds