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