简体   繁体   中英

Google Apps scripts- Contacts service not working for me

I am trying to learn Google Apps Scripts, a new bee out here, below is a small piece that I am trying to loop through all the contacts of the contact group "Dev Team" in my contacts.

function myFunction() {

var ui = DocumentApp.getUi();
var i = 0;
var cont = ContactsApp.getContactGroup('Dev Team').getContacts();

ui.alert('Please confirm', cont.length, ui.ButtonSet.YES_NO);  

while(cont[i])
{
  var name = cont[i].getPrimaryEmail();
  ui.alert('Please confirm',name,ui.ButtonSet.YES_NO); 
  if(name==null){break;}
  i++;   
}
ui.alert('out loop');
}

but the variable "name" is not getting any value or the code is not executing after it gets into the loop.

Not sure where i am missing, Please advice.

Regards, Saravana Kumar P.

Someone more educated can possibly fill in why, but the contacts actually works fine. The UI prompt seems to be the issue. If you condense your code down to:

function contactsTest(){
    var ui = DocumentApp.getUi();
    var group = ContactsApp.getContactGroup('Dev Team').getContacts();
    var i = 0;
    Logger.log(response);

      while(group[i])
        {
          var name = group[i].getPrimaryEmail();
          Logger.log(name);
          i++;
        }
  }

Then it appears to work. Not sure why the dialogue box screws it, but perhaps it has something to do with suspending the server side script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM