Take the 2-minute tour ×

I have an issue with Phonegap contacts.save. When I create a contact works perfectly in iOS and Android, but, when I try to update a contact, there are duplicates fileds as phoneNumbers, emails, urls, ims, addresses, I'm using Phonegap 2.1 and Xcode 4.5.1.

Someone could help me to solve this issue?. I appreciate your time. Thanks.

In resume:

  • navigator.contacts.create(); works correctly.
  • when I try to update a contact, save correctly, but, add phone numbers instead update.

My code is:

var options = new ContactFindOptions();
options.filter = 20;  //just it's an example. Looking for id 20.
var fields = ['id'];
var contact;   
    if (contacts.length==0) 
       contact = navigator.contacts.create();
       contact = contacts[0];

    var tContactName = new ContactName();
    tContactName.givenName = 'Name';
    tContactName.LastName = 'LastName';
    contact.name = tContactName;    

    var tPhoneNumbers[2];
    tPhoneNumbers[0] = new ContactField('work', '123456789012',true);
    tPhoneNumbers[1] = new ContactField('home', '120987654321', false);
    contact.phoneNumbers = tPhoneNumbers;

    contact.save(function(contact) {
       navigator.notification.alert('Saved sucessfully!!!',function(){},'Title');
    }, function(contactError) {
       navigator.notification.alert('Error contact save: '+contactError.code,function(){},'Title');
}, function(contactError) {
       navigator.notification.alert('Error contact find: '+contactError.code,function(){},'Title');
}, options);
share|improve this question

2 Answers 2

up vote 1 down vote accepted

The code is working exactly how is should according to the W3C Contact spec. That doesn't mean it makes sense though :)

Anyway, when you create a new array of phone numbers and set that to be equal to the contact.phoneNumbers property in effect you are adding phone numbers to the contact. If you want to edit/replace the existing phone numbers you need to request the phone numbers as part of your "fields". Then you need to loop through the existing phone numbers and edit them as you see fit.

Yup, it is counter-intuitive but that's the W3C api for you.

share|improve this answer
Can you please post an example. thanks –  Hardy Jul 11 '13 at 23:01

You have to assign value to already created phone numbers contact field instead of creating new value again for the phone numbers using new ContactField.

So here is the example to update phone numbers,

contact.tphoneNumbers[0].value = 123456789012 
contact.tphoneNumbers[1].value = 120987654321

then instead of using contact.phoneNumbers = tPhoneNumbers; on update you directly call the save method and that's it.

share|improve this answer

Your Answer


