问题
I'm trying to add contacts that are in MyContacts into other contact groups. I feel like i've written it correctly but it is not working:-
function myFunction() {
var MyContact = ContactsApp.getContactsByEmailAddress('XXXX.XXXX@Pearson.com');
var MyGroup = ContactsApp.getContactGroup('Sample');
MyGroup.addContact(MyContact);
}
XXXX.XXXX@Pearson.com is in my contacts list and I have already created the group Sample but I get the message of 'Cannot convert to . (line 4) Dismiss'. Line for being:-
MyGroup.addContact(MyContact);
Any ideas? I looked around and could not find an answer.
Regards Gary
回答1:
This sample code works if the group exists :
function addtContactTogroup() {
var contact = ContactsApp.getContact('emailAdress')
var group = ContactsApp.getContactGroup('groupName')
group.addContact(contact)
}
It's almost the same as yours, I know ! , but it doesn't throw any error ... please keep us informed it it fails for you.
回答2:
Zoe je zoiets als dit:
function myFunction() {
var Mycontacts = ContactsApp.getContactsByGroup("AnyGroupName");
for (var i=0; i<Mycontacts.length; i++) {
if (Mycontacts[i]) {
Mycontacts[i].addToGroup("AnyGroupNameWereYouLikeToPutIt");
}
}
}
来源:https://stackoverflow.com/questions/13231943/add-contact-to-a-contactgroup