Samsung Electronics logo

Adding Multiple Contacts in the Batch Mode



To create engaging applications with various contacts features, you must learn to add multiple contacts to an address book in the batch mode:

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

    addressbook = webapis.contact.getDefaultAddressBook();
    
  2. Define the items to be added as an array:

    var c1 = new webapis.Contact(
    {
       name: new webapis.ContactName({firstName:"Jeffrey", lastName:"Hyman"}),
       emails:[new webapis.ContactEmailAddress("user1@domain.com")]
    });
    
    var c2 = new webapis.Contact(
    {
       name: new webapis.ContactName({firstName:"Elton", lastName:"John"}),
       emails:[new webapis.ContactEmailAddress("user2@domain.com")]
    });
    
  3. Use the addBatch() method of the AddressBook interface to add the contacts in the array to the address book:

    addressbook.addBatch([c1, c2]);