Revision as of 09:59, 17 December 2008 by seppo_fn (Talk | contribs)

Removing message from Inbox in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search

Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Platform(s): S60 5th Edition
S60 5th Edition
Keywords: device.getServiceObject(), Service.IMessaging.GetList(), Service.IMessaging.Delete()
Created: (24 Nov 2008)
Last edited: seppo_fn (17 Dec 2008)


This code snippet shows how to delete a message from Messaging inbox using the Messaging Platform Service for S60 Web Runtime, introduced in S60 5th Edition.

It shows list of inbox messages (sms or mms) and allow user to delete any of them. The code snippet uses JavaScript WRT Messaging Services API. To get list of messages Service.IMessaging.GetList(criteria) method is used. criteria is the object which represents what messages we have to get. To get list of incoming messages criteria.Type = "Inbox" is used. To remove selected message Service.IMessaging.Delete(criteria) method is used with criteria.MessageId set to message id of message which is selected. To obtain access to service object for the Messaging Service API method getServiceObject("Service.Messaging", "IMessaging") is used.

Source file: RemovingMessage.html

Removing Message
<style type="text/css">
@import "removeMessage.css";
<script type="text/javascript" src="removeMessage.js"></script>
<body onLoad="setup();">
<h2>Message Remover</h2>
<table class="mainTable">
<input type="radio" name="choiseType" checked id="sms"
<input type="radio" name="choiseType" id="mms"
<input type="button" onClick="removeMessage();" value="Remove"><br>
<td colspan="2">
<select id="messageList" size="5" multiple>
<option disabled> </option>

Source file: removeMessage.css

h2  {
font-weight: bold;
text-align: center;
input {
font-weight: bold;
.mainTable {
width: 100%;
border: groove 1px gray;
border-collapse: collapse;
background-color: white;
td {
border: solid 1px gray;
padding: 5px;
margin: 0px;
border-collapse: collapse;
text-align: center;
vertical-align: middle;

Source file: removeMessage.js

// removeMessage.js
// Object is available through a Service API. Declare service object,
// that is used to access the messaging services.
var serviceObject = null;
* Java Script function.
* Closing window.

function rightSoftkeyFunction() {
* Java Script function, used object available through a Service API.
* Initializing main controls.

function setup() {
try {
document.getElementById("messageList").style.display = "none";
//Getting service object.
serviceObject = device.getServiceObject("Service.Messaging",
} catch (exception) {
alert("Service initialization error: " + exception);
try {
//Setting label and handler for right softkey.
menu.setRightSoftkeyLabel("Exit", rightSoftkeyFunction);
} catch (e) {
alert("Menu initialization error: " + e);
// Get list of all messages amd show it in SELECT object.
* Java Script function.
* Viewes messages in separate list.
* @param iterator List of messages, same as result.ReturnValue

function showMessages(iterator) {
var msgList = document.getElementById("messageList");
//Iterator is the list of the messages
//reset to set pointer to the first element.
var item;
// Clear current message list
while (msgList.length > 0) {
msgList.style.display = "block";
//Fetching values from iterator and addition it to the options.
//Value of option contains description of corresponding message.
while ((item = iterator.getNext()) != undefined) {
var node = document.createElement ("option");
node.value = item.MessageId;
node.appendChild (document.createTextNode(item.MessageType +
item.Sender + "|" +item.Subject));
if (msgList.length > 0) {
msgList.options[0].selected = true;
* Java Script function, using API from WRT 1.1 -- Messaging Service API.
* Gets list of messages.

function getMessageList() {
//Setup input params using dot syntax.
var criteria = new Object();
criteria.Type = "Inbox";
criteria.Filter = new Object();
criteria.Filter.MessageTypeList = new Array();
if (document.getElementById("sms").checked == true) {
criteria.Filter.MessageTypeList[0] = "SMS";
} else {
criteria.Filter.MessageTypeList[0] = "MMS";
try {
// Get list of messages
var result = serviceObject.IMessaging.GetList(criteria);
if(result.ErrorCode != 0) {
alert("Error in getting messages");
} catch(exception) {
alert("getList: " + exception);
* JavaScript function, uses API from WRT 1.1 - Messaging Service API.
* Removes the message which is selected in selection listbox.

function removeMessage() {
// Get reference to SELECT object which containing list of messages
var msgList = document.getElementById("messageList");
// Criteria indicating the message which is required to be deleted
var criteria = new Object();
// Find messages which are selected in selection listbox
for (var msgIndex = 0; msgIndex < msgList.length; msgIndex++) {
if (msgList.options[msgIndex].selected) {
// Get message id of selected message
var messageId = msgList.options[msgIndex].value;
// Radix of message id integer value
var radix = 10;
// Get numeric representation of the message id
criteria.MessageId = parseInt(messageId, radix);
// Delete the message
var result = serviceObject.IMessaging.Delete(criteria);
if (result.ErrorCode !== 0) {
// Remove message record from selection list
msgIndex = msgIndex - 1;


  • After starting the snippet list of messages, "Remove" button and "SMS/MMS"checkbox are shown on display.
  • To remove any message - user should select it in the list and choose "Remove" button.
  • After that required message will be deleted from phone's memory and from message list.
  • If checkbox is set to "sms" sms messages are processed;
  • If checkbox is set to "mms" mms messages are processed.

Supplementary material

You can see source file and executable application in attached zip archive. Archive is available for download at Removing_message_from_Inbox_in_WRT.zipCateogry:Messaging

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