Samsung Electronics logo

Managing Multiple Contacts in the Batch Mode



To create engaging applications with various contacts features, you must learn to manage multiple contacts in your address books in the batch mode:

  1. Retrieve the default address book using the getDefaultAddressBook() method of the ContactManager interface.

    var addressbook = webapis.contact.getDefaultAddressBook();
    
  2. Retrieve contacts stored in the address book by using the find() method of the AddressBook interface:

    var filter = new webapis.AttributeFilter("name.firstName", "CONTAINS", "Chris"};
    var sortMode = new webapis.SortMode("name.lastName", "ASC");
    
    try 
    {
       addressbook.find(contactsFoundCB, errorCallback, filter, sortMode);
    }
  3. To update contacts:
    1. Define the contact changes to be made in the success event handler of the find() method:

      function contactsFoundCB(contacts) 
      {
         /* Change the first names of all the found contacts */
         for (var i=0; i<contacts.length; i++) 
         {
            contacts[i].name.firstName = "Christopher";
         }
      
    2. Use the updateBatch() method to update multiple contacts asynchronously:

         /* Update all found contacts */
         addressbook.updateBatch(contacts);
      }
      
  4. To delete contacts, use the removeBatch() method in the success event handler of the find() method to delete multiple contacts asynchronously:

    function contactsFoundCB(contacts)
    {
       /* Delete the first 2 found contacts */
       addressbook.removeBatch([contacts[0].id, contacts[1].id]);
    }