ContactManager.getAll()

This API is available on Firefox OS for privileged or certified applications only.

Summary

The getAll method is used to access a sorted list of contact from the device's contact database. This method is best suited to access a large data set, where find() is better suited for a small data set.

Syntax

var instanceOfDomCursor = window.navigator.mozContacts.getAll(options);

Parameters

options
The getAll method expects some options to sort and filter the contacts. The possible options are the following:
Sort options
  • sortBy: A string representing the field by which the results of the search are sorted. Currently only givenName and familyName are supported.
  • sortOrder: A string indicating the result's sort order. Possible values are descending or ascending.
Filter options
  • filterBy: An array of strings representing all the fields to filter by.
  • filterValue: The value to match against.
  • filterOp: The filter comparison operator to use. Possible values are equals, startsWith, and match, the latter being specific to telephone numbers.
  • filterLimit: The number of contacts to retrieve.

Return value

A DOMCursor object to handle the success or error of the operation. In case of success, the request's result is a mozContact object. To move to the next result, call the cursor's continue() method.

Example

var filter = {

  sortBy: name,
  
}

var request = window.navigator.mozContacts.getAll(filter);
var count = 0;

request.onsuccess = function () {
  if(this.result) {
    count++;

    // Display the name of the contact
    console.log("Name of Contact" + this.result.name);

    // Display the Mobile number of the contact
Ā    console.log("Number of Contact" + this.result.tel[0].value);
Ā    

    // Move to the next contact which will call the request.onsuccess with a new result
    this.continue();

  } else {
    console.log(count + 'contacts found.');
  }
}

request.onerror = function () {
  console.log('Something goes wrong!');
}

Specifications

Specification Status Comment
Contacts Manager API
The definition of 'Contacts Manager API' in that specification.
Working Draft Ā 
vCard Format Specification IETF RFC RFC 6350

Browser compatibility

Supported in Firefox Mobile 18 and Firefox OS 1.1.

See also