Add Contact to a ContactGroup

巧了我就是萌 提交于 2021-02-10 22:50:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!