0

I am trying to add/create/get contactGroup based on each contact info by Google Apps Script. But I have faced asynchronous error while I am using app-script/contacts API. I can't get latest contactGroup list(it doesn't include contactGroup just added) although I added new contactGroup

I made Google Apps Script by contacts API that can classify each contact to different contactGroup based on email.

function test(){
  var group1 = ContactsApp.createContactGroup('group1');
  var groupList1 = ContactsApp.getContactGroup('group1');
  Logger.log(groupList1); // got contactGroup Object

  var group2 = ContactsApp.createContactGroup('group2');
  var groupList2 = ContactsApp.getContactGroup('group2');
  Logger.log(groupList2); // got contactGroup Object

  var group3 = ContactsApp.createContactGroup('group3');
  var groupList3 = ContactsApp.getContactGroup('group3');
  Logger.log(groupList3); // null

  var group4 = ContactsApp.createContactGroup('group4');
  var groupList4 = ContactsApp.getContactGroup('group4');
  Logger.log(groupList4); // null

  var group4 = ContactsApp.createContactGroup('group4');
  var groupList4 = ContactsApp.getContactGroup('group4');
  Logger.log(groupList4); // null

}

so, I had to wait about 5000ms to get object before calling getContactGroup function I think there must be a solution to avoid this. Please help if there is anyone who has ever faced a similar issue

enter image description here

Sandokan
  • 667
  • 5
  • 14
  • So far there's no information regarding this error when calling Contacts API asynchronously. You will need to call the API again after modifying the `contactGroup`. – Jessica Rodriguez Apr 12 '19 at 15:06
  • Hi, Jess. Thanks for your comment. Yes, I know, in fact, that is my issue. I have to call API after got contactGroup. But it takes so much time to wait until GSuite will return correct value of contactGroup. I have 5000 contacts, so I have to wait endless – Sandokan Apr 13 '19 at 17:51

0 Answers0