deletePhoneField() always deletes the first phone number

28 views
Skip to first unread message

Václav Benýšek

unread,
Jan 9, 2020, 8:14:02 AM1/9/20
to Google Apps Script Community
Hello,

I would like to be able to remove specific phone numbers by their type, yet Google ContactsApp API won't allow me do that as it always removes the first phone number no matter what. Please run the code below to see.

function deleteSpecificPhoneNumber(){
  var contact = ContactsApp.createContact("John", "Doe", "te...@test.com");
  contact.addPhone(ContactsApp.Field.HOME_PHONE, "111");
  contact.addPhone(ContactsApp.Field.WORK_PHONE, "999");
  var phoneFields = contact.getPhones(ContactsApp.Field.WORK_PHONE);
  phoneFields[0].deletePhoneField();
}

Expected result would be to have John Doe with only 111 phone number, yet you'll end up with 999. This has been reported 4 years ago to Google and they don't seem to care enough to fix it. 

Any workaround thoughts? I already tried to set the phone number as primary which moved it to the first place, but that didn't do the trick.

Thanks
Vasek
Reply all
Reply to author
Forward
0 new messages