Namespaces

Variants
Actions

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.

Revision as of 06:54, 5 October 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Retrieving contacts info in Symbian Web Runtime

From Wiki
Jump to: navigation, search

This code example shows how to retrieve contacts information on Symbian Web Runtime.

Article Metadata
Code ExampleTested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 5th Edition
S60 5th Edition
Article
Keywords: device.getServiceObject(), Service.Contact.GetList()
Created: MiGryz (10 Dec 2008)
Last edited: hamishwillee (05 Oct 2012)

Contents

Overview

The example uses the Contact Platform Service, 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.

Source: phonebook.html

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="phonebook.js" />
<title></title>
</head>
<body onload="init()">
<!-- input field for search string -->
<input id="searchstring" type="text"></input>
<input type="button" value="Search" onclick="doRefresh();"></input>
<!-- Table for displaying contacts info -->
<table id="maintable" cellspacing=1 cellpadding=1 border=1 cols=4>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Phone</th>
<th>Email</th>
</tr>
</table>
</body>
</html>

Source: phonebook.js

// contacts system service object
var phonebook;
// system error code
var NO_ITEMS_ERROR_CODE = 1012;
 
/**
* 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" );
return;
}
 
// Refreshing info
doRefresh();
}
 
/**
* 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';
 
var searchString = document.getElementById('searchstring').value;
if(searchString != "") {
// if we have some search string add search parameter to criteria
criteria.Filter = new Object();
criteria.Filter.SearchVal = searchString;
}
 
// 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" );
return;
}
 
// receiving a handle to table to display info
var table = document.getElementById('maintable');
// cleaning table and adding header
while(table.rows[0] != undefined) {
table.deleteRow(0);
}
table.insertRow(0);
table.rows[0].innerHTML = "<th>Firstname</th><th>Lastname</th>" +
"<th>Phone</th><th>Email</th>";
 
// looking for error code returned by GetList
if(contacts.ErrorCode != 0) {
// If error code is not "no suitable items", show alert.
// Otherwise leave the function.
if(contacts.ErrorCode != NO_ITEMS_ERROR_CODE) {
alert(contacts.ErrorMessage);
}
return;
} else {
// filling table with received data
var table = document.getElementById('maintable');
var i; // iterator
var item; // pointer to item in received list
for(i = 0;
(item = contacts.ReturnValue.getNext()) != undefined;
++i) {
table.insertRow(i + 1);
var result = "<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;
}
}
}

Postconditions

  • Shows a table with all contacts.
  • Typing text in the input field and pressing the "Search" button will update the information in the table, showing only items that are returned by standard search (that have common letters in first name or last name).

Supplementary material

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

This page was last modified on 5 October 2012, at 06:54.
77 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.

×