Delete contact

46 views
Skip to first unread message

Andrea

unread,
May 2, 2019, 9:34:32 AM5/2/19
to Google Apps Script Community
Dear,
I'm not able to delete a contact.
I can't understand what I'm wrong
I'm going crazy!

// The code below retrieves a contact with the email address "john...@example.com"
// and then deletes that contact.
var contact = ContactsApp.getContact('john...@example.com');
ContactsApp.deleteContact(contact);

This is my function.

 function delcon() { 
   var emailToDelete = 'te...@domain.com';
   var results = ContactsApp.getContactsByEmailAddress(emailToDelete);
  
   // even with this line the code does not work
  //var results= ContactsApp.getContact(emailToDelete);
   
 
 ContactsApp.deleteContact(results);
 
 };

Thank you for your precious help

Andrea

Abdellah NAJIM

unread,
May 2, 2019, 10:34:30 AM5/2/19
to google-apps-sc...@googlegroups.com, andrea....@consultant.solgroup.com
The difference between  getContact and getContactsByEmailAddress is that the first one return Contact, but the second return Array of contacts.

function delcon() { 
   var emailToDelete = 'te...@domain.com';
   var results = ContactsApp.getContactsByEmailAddress(emailToDelete); 
  ContactsApp.deleteContact(results[0]);
 }

ABDELLAH NAJIM



IMPORTANT:
This is a business and not a personal e-mail, this message and its attachments are confidential and may also be legally privileged.
If you are not the intended recipient, or have received this e-mail in error, please notify immediately the sender and delete this message and all its attachments.

Any unauthorized review, copying, disclosure, dissemination, or distribution of this message and/or its attachments is strictly forbidden.



--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-script-community.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/4462fadc-1e7b-46b7-a48e-1f2df51a48fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrea

unread,
May 2, 2019, 10:48:02 AM5/2/19
to Google Apps Script Community
Dear Najim, thanks for reply.
Unfortunely your code not working for me :(

This is the contact to be deleted

Contact.jpg


This is the function
 function delcon2() { 
   var emailToDelete = 'pi...@pippo.com';
   var results = ContactsApp.getContactsByEmailAddress(emailToDelete); 
  ContactsApp.deleteContact(results[0]);
 }


This is the Execution 

DeleteContact.jpg


I have no idea why it doesn't work.
If you have another suggestion I would be very grateful
Grazie!
Andrea


On Thursday, 2 May 2019 16:34:30 UTC+2, Abdellah NAJIM wrote:
The difference between  getContact and getContactsByEmailAddress is that the first one return Contact, but the second return Array of contacts.

function delcon() { 
   var emailToDelete = 'te...@domain.com';
   var results = ContactsApp.getContactsByEmailAddress(emailToDelete); 
  ContactsApp.deleteContact(results[0]);
 }

ABDELLAH NAJIM


Le jeu. 2 mai 2019 à 15:34, Andrea <andrea....@consultant.solgroup.com> a écrit :
Dear,
I'm not able to delete a contact.
I can't understand what I'm wrong
I'm going crazy!

// The code below retrieves a contact with the email address "joh...@example.com"

// and then deletes that contact.
var contact = ContactsApp.getContact('john.d...@example.com');
ContactsApp.deleteContact(contact);

This is my function.

 function delcon() { 
   var emailToDelete = 'te...@domain.com';
   var results = ContactsApp.getContactsByEmailAddress(emailToDelete);
  
   // even with this line the code does not work
  //var results= ContactsApp.getContact(emailToDelete);
   
 
 ContactsApp.deleteContact(results);
 
 };

Thank you for your precious help

Andrea



IMPORTANT:
This is a business and not a personal e-mail, this message and its attachments are confidential and may also be legally privileged.
If you are not the intended recipient, or have received this e-mail in error, please notify immediately the sender and delete this message and all its attachments.

Any unauthorized review, copying, disclosure, dissemination, or distribution of this message and/or its attachments is strictly forbidden.



--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

Andrea

unread,
May 2, 2019, 10:58:42 AM5/2/19
to Google Apps Script Community
Najim, sorry.... some minutes ago i wrote that the code is not working ....
the code work and the contact is deleted.
but..... is it normal that the deletion of a single contact (my address book is empty!) takes so much time (427 sec.)?

[19-05-02 07:37:06:492 PDT] Starting execution
[19-05-02 07:44:14:093 PDT] ContactsApp.getContactsByEmailAddress([pi...@pippo.com]) [427.586 seconds]
[19-05-02 07:44:14:272 PDT] Contact.deleteContact() [0.178 seconds]
[19-05-02 07:44:14:272 PDT] ContactsApp.deleteContact([Contact]) [0.178 seconds]
[19-05-02 07:44:14:275 PDT] Execution succeeded [427.767 seconds total runtime]

Thanks you very much.
Andrea

On Thursday, 2 May 2019 16:34:30 UTC+2, Abdellah NAJIM wrote:
The difference between  getContact and getContactsByEmailAddress is that the first one return Contact, but the second return Array of contacts.

function delcon() { 
   var emailToDelete = 'te...@domain.com';
   var results = ContactsApp.getContactsByEmailAddress(emailToDelete); 
  ContactsApp.deleteContact(results[0]);
 }

ABDELLAH NAJIM


Le jeu. 2 mai 2019 à 15:34, Andrea <andrea....@consultant.solgroup.com> a écrit :
Dear,
I'm not able to delete a contact.
I can't understand what I'm wrong
I'm going crazy!

// The code below retrieves a contact with the email address "joh...@example.com"

// and then deletes that contact.
var contact = ContactsApp.getContact('john.d...@example.com');
ContactsApp.deleteContact(contact);

This is my function.

 function delcon() { 
   var emailToDelete = 'te...@domain.com';
   var results = ContactsApp.getContactsByEmailAddress(emailToDelete);
  
   // even with this line the code does not work
  //var results= ContactsApp.getContact(emailToDelete);
   
 
 ContactsApp.deleteContact(results);
 
 };

Thank you for your precious help

Andrea



IMPORTANT:
This is a business and not a personal e-mail, this message and its attachments are confidential and may also be legally privileged.
If you are not the intended recipient, or have received this e-mail in error, please notify immediately the sender and delete this message and all its attachments.

Any unauthorized review, copying, disclosure, dissemination, or distribution of this message and/or its attachments is strictly forbidden.



--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

Federico Granata

unread,
May 2, 2019, 11:26:36 AM5/2/19
to google-apps-sc...@googlegroups.com
As you can see from your log what takes 427 seconds is not the deletion process but the getContactsByEmailAddress method.
To me it looks like a glitch ... have you tried to run it multiple time with different bogus contacts ?
You get the same results or it's usually faster?

___
Federico Granata


var contact = ContactsApp.getContact('john...@example.com');
ContactsApp.deleteContact(contact);

This is my function.

 function delcon() { 
   var emailToDelete = 'te...@domain.com';
   var results = ContactsApp.getContactsByEmailAddress(emailToDelete);
  
   // even with this line the code does not work
  //var results= ContactsApp.getContact(emailToDelete);
   
 
 ContactsApp.deleteContact(results);
 
 };

Thank you for your precious help

Andrea



IMPORTANT:
This is a business and not a personal e-mail, this message and its attachments are confidential and may also be legally privileged.
If you are not the intended recipient, or have received this e-mail in error, please notify immediately the sender and delete this message and all its attachments.

Any unauthorized review, copying, disclosure, dissemination, or distribution of this message and/or its attachments is strictly forbidden.



--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

IMPORTANT:
This is a business and not a personal e-mail, this message and its attachments are confidential and may also be legally privileged.
If you are not the intended recipient, or have received this e-mail in error, please notify immediately the sender and delete this message and all its attachments.

Any unauthorized review, copying, disclosure, dissemination, or distribution of this message and/or its attachments is strictly forbidden.



--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

Andrea

unread,
May 2, 2019, 11:41:37 AM5/2/19
to Google Apps Script Community
I did a test with two Google accounts and with different contacts. 
The result (many many time) is always the same.
I hope this slowness is due to a temporary problem with Google's servers

Tomorrow I'll try again (with fingers crossed :D )

Grazie
Best regards
Andrea

On Thursday, 2 May 2019 17:26:36 UTC+2, Federico Granata wrote:
As you can see from your log what takes 427 seconds is not the deletion process but the getContactsByEmailAddress method.
To me it looks like a glitch ... have you tried to run it multiple time with different bogus contacts ?
You get the same results or it's usually faster?

___
Federico Granata


Il giorno gio 2 mag 2019 alle ore 16:58 Andrea <andrea....@consultant.solgroup.com> ha scritto:
Najim, sorry.... some minutes ago i wrote that the code is not working ....
the code work and the contact is deleted.
but..... is it normal that the deletion of a single contact (my address book is empty!) takes so much time (427 sec.)?

[19-05-02 07:37:06:492 PDT] Starting execution
[19-05-02 07:44:14:093 PDT] ContactsApp.getContactsByEmailAddress([pipp...@pippo.com]) [427.586 seconds]
[19-05-02 07:44:14:272 PDT] Contact.deleteContact() [0.178 seconds]
[19-05-02 07:44:14:272 PDT] ContactsApp.deleteContact([Contact]) [0.178 seconds]
[19-05-02 07:44:14:275 PDT] Execution succeeded [427.767 seconds total runtime]

Thanks you very much.
Andrea

On Thursday, 2 May 2019 16:34:30 UTC+2, Abdellah NAJIM wrote:
The difference between  getContact and getContactsByEmailAddress is that the first one return Contact, but the second return Array of contacts.

function delcon() { 
   var emailToDelete = 'te...@domain.com';
   var results = ContactsApp.getContactsByEmailAddress(emailToDelete); 
  ContactsApp.deleteContact(results[0]);
 }

ABDELLAH NAJIM


Le jeu. 2 mai 2019 à 15:34, Andrea <andrea....@consultant.solgroup.com> a écrit :
Dear,
I'm not able to delete a contact.
I can't understand what I'm wrong
I'm going crazy!

// The code below retrieves a contact with the email address "joh...@example.com"
// and then deletes that contact.
var contact = ContactsApp.getContact('john.d...@example.com');
ContactsApp.deleteContact(contact);

This is my function.

 function delcon() { 
   var emailToDelete = 'te...@domain.com';
   var results = ContactsApp.getContactsByEmailAddress(emailToDelete);
  
   // even with this line the code does not work
  //var results= ContactsApp.getContact(emailToDelete);
   
 
 ContactsApp.deleteContact(results);
 
 };

Thank you for your precious help

Andrea



IMPORTANT:
This is a business and not a personal e-mail, this message and its attachments are confidential and may also be legally privileged.
If you are not the intended recipient, or have received this e-mail in error, please notify immediately the sender and delete this message and all its attachments.

Any unauthorized review, copying, disclosure, dissemination, or distribution of this message and/or its attachments is strictly forbidden.



--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.


IMPORTANT:
This is a business and not a personal e-mail, this message and its attachments are confidential and may also be legally privileged.
If you are not the intended recipient, or have received this e-mail in error, please notify immediately the sender and delete this message and all its attachments.

Any unauthorized review, copying, disclosure, dissemination, or distribution of this message and/or its attachments is strictly forbidden.



--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

andythelorenz

unread,
May 4, 2019, 7:18:25 AM5/4/19
to Google Apps Script Community

I think problem could depend array is empty
one should probably test if condition is true (mail exist)
before run the delete command

I have already had lot of problem with contact,
script more or less blocked the system,
unfortunatly I don't remember well the reason

I think, if I remebr well, this depended I used export function in the precedent application
(because new one didn't have import - export function)

More or less i got problem, it was slow, it blocked system, etc..

So I cheched mails inside
and I have a mail wasn't see by the script,
it was invisible, not intercettable, this mail probably created problem

In reality I had one mail of difference. This email was one of my mail by the way (myself)

So, I think there are some bugs, but I suppose they can depend you used the old version of contact

I think if one check the mail before delete or use some try an catch can control better the situation


Andrea

unread,
May 6, 2019, 3:45:05 AM5/6/19
to Google Apps Script Community
Thank you all for your help !

I think (hope) that I have understand the origin of problem.
I thought my Contacts was empty but it really wasn't.
I have not considered the contacts coming from Directory (they are really many).
I thought the script only considered my personal contacts (excluding the corporate ones).
I'm still doing some tests but now the speed is correct.
I filtered the contact search based on a specific ContactGroup membership.

Grazie !
Best regards
Andrea
Reply all
Reply to author
Forward
0 new messages