3

(new to Google Script {about 2 weeks} so please be verbose)

I have tried everything I could find or think of to display the custom labels for a contact's list of email address. This has been very frustrating. When I search I get a lot of hits for gmail message labels, but nothing for custom labels for the email address within an individual contact.

Long term goal is to build an auto forwarder for my son’s Boy Scout Troop, taking baby steps to get there.

Some of the boys want to be notified by SMS, some by email. Since some have actual emails (used with attachments) and mobile phones (used for reminders), there is a need for custom contact email labels. I can make a list of all of the contact groups and I can make a list of all of the contact names within each group. I can even get all of the email address for each contact. But I can’t get the custom labels for a contact’s list of emails.

It is beyond me why the “getLabel” method does not do all of the “behind the curtain” work and return the label text regardless of the label type (custom or built in).

Any guidance would be appreciated.

    function Get_Groups_Contacts(GroupList) 
    {
      var groups = ContactsApp.getContactGroups();  //get the list of groups
      for (var i in groups)  //for each item in the group list ...
      {
        for (var n=0; n<=15; n++)  //need to setup retries since the next part sometimes has server issues
        {
          try  //trap errors
          { 
            var cont = groups[i].getContacts()  //get the list of contacts that belong to the group
            var arrCont= []  //define the temp storage
            for (var j in cont)  //step through each contact
            {
    //I can store a list of contact names…
              arrCont.push(cont[j].getFullName() );  //get the contact's full name
    // but am trying to switch to specific email address….
              var eml = cont[j].getEmails();  // the list of all email address for a contact
    //now the messy part, trying to figure things out
    //lists the built in labels but not the custom labels
              for (k in eml) Logger.log(typeof eml[k].getLabel() + "??" + eml[k].getLabel() + "--" + eml[k].getAddress());
              for (k in eml)
              {
                try 
                {
                  var x = eml[k].getLabel();
                  Logger.log(k + " !!" + typeof x + "??" + x + "--" + eml[k].getAddress() + "**" + "hello");
    //              var oneeml = eml[k];
                  var oneeml = cont[j].getEmails("Other");
                  Logger.log("xxxxxxxxxxxxxxxxxxxxxxxx");
                  Logger.log("oneeml " + oneeml);
                  //Logger.log(oneeml.getLabel())
                  Logger.log("zzzzzzzzzzzzzzzzzzzzzzzz");
                  for (zz in oneeml) Logger.log(oneeml[zz]);
                  for (zz in oneeml) 
                    if (zz == "setAsPrimary") Logger.log(zz)
                    else if (zz == "setDisplayName") Logger.log(zz)
                    else if (zz == "setAddress") Logger.log(zz)
                    else if (zz == "setLabel") Logger.log(zz)
                    else if (zz == "deleteEmailField") Logger.log(zz)
                    else Logger.log(oneeml[zz]())
                    ;
                }
                catch(ext)
                {
                  Logger.log("inner catch");
                  Logger.log(ext.message);
                }
              }
            } 
    //end of the messy part
            GroupList[groups[i].getGroupName()] = arrCont  //store the list in the property
            break;  //go on to the next group
          }  //end of try
          catch(err)  //catch the error here
          {
    //        Logger.log (n + " error message" + err.message);  //debug
           Logger.log ("n=" + n);  //debug
            sleep((Math.pow(2,n) + (Math.random(0, 1000) / 100)) );  //increasing random sleep time waiting for the server
          }  //end of catch
          finally  //always do this part
          {
            cont = undefined;  //cleanup
            arrCont = undefined;  //cleanup
          }  //end of error traping
        }  //end of retry loop
      }  //end for each group item
    };  //end of function List_Groups_Contacts()
Mogsdad
  • 44,709
  • 21
  • 151
  • 275

0 Answers0