user1476864
user1476864

Reputation: 23

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.

Upvotes: 0

Views: 171

Answers (1)

HDCerberus
HDCerberus

Reputation: 2143

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.

Upvotes: 1

Related Questions