Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Removing contacts in Symbian Web Runtime

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleTested with
Devices(s): Nokia 5800 XpressMusic
Platform(s): S60 5th Edition
S60 5th Edition
Keywords: device.getServiceObject(), Service.Contact.GetList(), Service.Contact.Delete()
Created: MiGryz (10 Dec 2008)
Last edited: hamishwillee (04 Oct 2012)



This code snippet shows how to remove contacts from the phone book using the Contacts Platform Service for Symbian Web Runtime. This service was introduced in S60 5th Edition.

To obtain access to the service object for the Contact Service API, the device.getServiceObject("Service.Contact", "IDataSource") method is used.

After setting the correct values for the criteria object (criteria.Type and criteria.Filter), the IDataSource.GetList(criteria) method is used to retrieve information.

Method IDataSource.Delete(criteria) is used to remove contacts.

Source: phonebookrem.html

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="phonebookrem.js" />
<body onload="init()">
<!-- Table for displaying contacts info -->
<table id="maintable" cellspacing=1 cellpadding=1 border=1 cols=4>
<input type="button" value="Remove selected" onclick="doRemove();" />

Source: phonebookrem.js

// contacts system service object
var phonebook;
// IDs of contacts to be removed
var ids = new Array();
// system error code
* Setting default data on application load

function init() {
// getting contacts system service object
try {
phonebook = device.getServiceObject("Service.Contact", "IDataSource");
} catch(err) {
alert( "No Contact service available" );
// Refreshing info
* function refreshes information in table

function doRefresh() {
// Criteria object for making a GetList call to receive
// contacts information
var criteria = new Object();
criteria.Type = 'Contact';
// making a call to service to receive a list of suitable items
try {
contacts = phonebook.IDataSource.GetList(criteria);
} catch(err) {
alert( "Error retrieving contacts information" );
// receiving a handle to table to display info
var table = document.getElementById('maintable');
// cleaning table and adding header
while(table.rows[0] != undefined) {
table.rows[0].innerHTML = "<th>D</th><th>Firstname</th>" +
// looking for error code returned by GetList
if(contacts.ErrorCode != 0) {
// If error code is not "no suitable items", show alert.
// Otherwise just leave the function.
if(contacts.ErrorCode != NO_ITEMS_ERROR_CODE) {
} else {
// filling table with received data and adding checkboxes into the
// first columns
var i; // iterator
var item; // pointer to item in received list
for(i = 0;
(item = contacts.ReturnValue.getNext()) != undefined;
++i) {
table.insertRow(i + 1);
ids[i + 1] =;
var result = "<td><input name=\"check" +
"\" type=\"checkbox\"></input></td><td>";
if(item.FirstName != undefined) {
result += item.FirstName.Value;
result += "</td><td>";
if(item.LastName != undefined) {
result += item.LastName.Value;
result += "</td><td>";
if(item.MobilePhoneGen != undefined) {
result += item.MobilePhoneGen.Value;
result += "</td><td>";
if(item.EmailGen != undefined) {
result += item.EmailGen.Value;
result += "</td>";
table.rows[i + 1].innerHTML = result;
* function removes selected items from the contacts list

function doRemove( ) {
// criteria object for deleting contacts
var criteria = new Object();
criteria.Type = 'Contact';
criteria.Data = new Object();
criteria.Data.IdList = new Array();
var action = false;
var table = document.getElementById('maintable');
var count = table.rows.length;
var iterator = 0;
// filling criteria IdList with item ids to delete (according to marked
// checkboxes)
for (var i = 1; i < count; i++) {
if (table.rows[i].cells[0].childNodes[0].checked == true) {
action = true;
criteria.Data.IdList[iterator++] = ids[i];
// if there are marked checkboxes delete items
if (action) {
try {
var result = phonebook.IDataSource.Delete(criteria);
} catch(err) {
alert( "Error removing data" );
// update info in table


  • The application shows a table with all contacts. Each row contains a checkbox.
  • Mark some of the checkboxes and select "Remove contacts" to remove the checked items from the phone book.

Supplementary material

You can view source file and executable application in the attached ZIP archive. The archive is available for download at Media:Removing contacts in

See also

This page was last modified on 4 October 2012, at 05:23.
25 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.