×
Namespaces

Variants
Actions
(Difference between revisions)

Adding contact in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot change of template (Template:CodeSnippet) - now using Template:ArticleMetaData)
hamishwillee (Talk | contribs)
m (Hamishwillee - Fix minor typo)
Line 1: Line 1:
 +
[[Category:Symbian Web Runtime]][[Category:Code Examples]][[Category:PIM]][[Category:S60 5th Edition]][[Category:Code Snippet]]
 
__NOTOC__
 
__NOTOC__
 
__NOEDITSECTION__
 
__NOEDITSECTION__
Line 10: Line 11:
 
|creationdate=December 18, 2008
 
|creationdate=December 18, 2008
 
|keywords=device.getServiceObject(), Service.Contact.Add()
 
|keywords=device.getServiceObject(), Service.Contact.Add()
 
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 
|sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 
|capabilities=<!-- Capabilities required (e.g. Location, NetworkServices. -->)
 
 
|author=[[User:MiGryz]]
 
|author=[[User:MiGryz]]
 
}}
 
}}
Line 132: Line 130:
 
* [[CS001235 - Retrieving contacts info in WRT]]
 
* [[CS001235 - Retrieving contacts info in WRT]]
 
* [[CS001243 - Removing contacts in WRT]]
 
* [[CS001243 - Removing contacts in WRT]]
 
[[Category:Symbian Web Runtime]][[Category:Code Examples]][[Category:PIM]][[Category:S60 5th Edition]][[Category:Code Snippet]]
 

Revision as of 06:54, 15 August 2011

Template:KBCS

Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 5th Edition
S60 5th Edition
Article
Keywords: device.getServiceObject(), Service.Contact.Add()
Created: MiGryz (18 Dec 2008)
Last edited: hamishwillee (15 Aug 2011)

Overview

This code snippet shows how to add contacts to the device's default phone book using the Contact Platform Service for S60 Web Runtime 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.Data), the IDataSource.Add(criteria) method is used to add the new contact.

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()">
<div id="inputdata">
First Name: <input id="firstname" type="text"></input><br />
Last Name: <input id="lastname" type="text"></input><br />
Phone number: <input id="phonenumber" type="text"></input><br />
E-Mail: <input id="email" type="text"></input><br />
<input type="button" value="Add" onclick="doSave();" />
</div>
</body>
</html>

Source: phonebook.js

// contacts system service object
var phonebook;
 
/**
* 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;
}
}
 
/**
* function adds an item to the default phonebook
*/

function doSave() {
// Criteria object for adding contacts
var criteria = new Object();
criteria.Type = 'Contact';
criteria.Data = new Object();
 
// demanding first name, but that is not essential
if(document.getElementById('firstname').value == "") {
alert("You should input firstname");
return;
}
 
// adding First Name parameter to new item
criteria.Data.FirstName = new Object();
criteria.Data.FirstName.Value =
document.getElementById('firstname').value;
// adding other parameters if present
if(document.getElementById('lastname').value != "") {
criteria.Data.LastName = new Object();
criteria.Data.LastName.Value =
document.getElementById('lastname').value;
}
if(document.getElementById('phonenumber').value != "") {
criteria.Data.MobilePhoneGen = new Object();
criteria.Data.MobilePhoneGen.Value =
document.getElementById('phonenumber').value;
}
if(document.getElementById('email').value != "") {
criteria.Data.EmailGen = new Object();
criteria.Data.EmailGen.Value =
document.getElementById('email').value;
}
 
var result = 0;
try {
result = phonebook.IDataSource.Add(criteria);
} catch(err) {
alert( "error saving data" );
return;
}
if(result.ErrorCode != 0) {
alert(result.ErrorMessage);
}
}

Postconditions

  • Filling in the fields and selecting "Add" will add a new item to the default phone book.

Supplementary material

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

See also

134 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.

×