I am working on an apps script that writes contact info (name and email) from google sheet into google contacts.
there are 3 columns on google sheet, the first column is a timestamp, the second col is email, and the third col is name.
the Apps script works, as adding contact to google contact, however, I want when any email removed from the google sheet, that contact info removes from google contacts as well, upon google sheet update/edit. I tried some, but stuck and could not make it. I am new to Apps script.
I am grateful if help me with the script.
Here is what I got:
function AddToGoogleContacts() {
var sheet = SpreadsheetApp.getActive().getSheetByName("sheet1");
for (var i = 0; i < sheet.getLastRow()-1; i++) {
var contactEmail = sheet.getRange(i+2,2,1,2).getValue();
var myContact = ContactsApp.getContact(contactEmail);
if (myContact === null){ ContactsApp.createContact(sheet.getRange(i+2,3,1,2).getValue(),"",sheet.getRange(i+2,2,1,2).getValue());
}
}
}