Avi E. Koenig
Avi E. Koenig

Reputation: 379

Issue updating a contact

I am trying to write a function for google sheets that will update a contact

The function so far gets the target contact but when I try to make an update nothing happens. I look up under contacts and also ContactsApp.getContacts() reflects the data was unchanged when I run it.

function editContact() {
    //get highlighted (active) cell data and first cell in its row(id)
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getActiveSheet();
    var aCell = sheet.getActiveCell();
    var id = grabId(aCell)

    var strArray = [];
    //fetch contact
    var contact = ContactsApp.getContactById(id);//works
    contact.setFamilyName('Doe-Smith');//does NOT work
    var contactName = contact.getFullName();//grabs old unaffected name
    strArray.push("contact", contactName);

    var title = "Target cell info"
    var str = stringMaker(strArray)

    showOutputBox(str, title);
}

I get no indication of error at all. Your assistance in this matter is much appreciated.

Upvotes: 0

Views: 47

Answers (2)

ziganotschka
ziganotschka

Reputation: 26836

The problem seems to be related to missleading documentation, where it states

getFullName() Gets the full name (given name and last name) of the contact as a string.

In reality, FullName as it is refers to the display name in Google Contacts.

Try the following code:

  Logger.log('given: '+contact.getGivenName());
  Logger.log('last: '+contact.getFamilyName());
  Logger.log('family: '+contact.getFullName());
  contact.setGivenName('Joe');
  contact.setFamilyName('Doe-Smith');
  contact.setFullName('Testname');
  Logger.log('given: '+contact.getGivenName());
  Logger.log('last: '+contact.getFamilyName());
  Logger.log('family: '+contact.getFullName());

You will see that all three parameters have been changed, but FullName is an independent parameter, rather than a combination of the given and family name.

So, as a workaround, for the moment you will need to set and get given and family name separately.

Upvotes: 1

Avi E. Koenig
Avi E. Koenig

Reputation: 379

Seems the method works after all but does not reflect in the contacts.google.com until I make an edit manually to affected contact.

90% sure they will prove I am a dummie but 10% sure I'm actually right and this is indeed a bug.

https://issuetracker.google.com/issues/140817923

Upvotes: 0

Related Questions