Removing message from Inbox in Symbian Web Runtime
m (Unprotected "CS001241 - Removing message from Inbox in WRT") |
|||
| Line 9: | Line 9: | ||
|subcategory=Messaging | |subcategory=Messaging | ||
|creationdate=December 18, 2008 | |creationdate=December 18, 2008 | ||
| − | |keywords=device.getServiceObject(), Service. | + | |keywords=device.getServiceObject(), Service.Messaging.Delete() |
}} | }} | ||
| − | |||
==Overview== | ==Overview== | ||
| − | |||
| − | + | This code snippet shows how to delete a message from the Inbox using the Messaging Platform Service for S60 Web Runtime, introduced in S60 5th Edition. | |
| − | To | + | To obtain access to the service object for the Messaging Service API, the <tt>device.getServiceObject("Service.Messaging", "IMessaging")</tt> method is used. |
| − | + | ||
| − | + | ||
| − | + | ==Source== | |
| − | + | ||
| − | + | The HTML <tt>select</tt> component contains the messages: | |
<code xml> | <code xml> | ||
| − | < | + | <select size="5" id="messageList" multiple></select><br /> |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | </ | + | |
</code> | </code> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
<code javascript> | <code javascript> | ||
| − | + | var serviceObj = null; | |
| − | // | + | // Initializes the widget |
| − | + | function init() { | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | function | + | |
try { | try { | ||
| − | + | serviceObj = device.getServiceObject("Service.Messaging", | |
| − | + | ||
| − | + | ||
"IMessaging"); | "IMessaging"); | ||
| − | } catch ( | + | } catch (ex) { |
| − | alert("Service | + | alert("Service object cannot be found."); |
return; | return; | ||
} | } | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
| − | / | + | </code> |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | <code javascript> | |
| − | + | // Removes the message which is selected in the list box. | |
| − | + | function removeMessage() { | |
| − | + | // Get a reference to SELECT object which contains the list of messages | |
| + | var messageList = document.getElementById("messageList"); | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
var criteria = new Object(); | var criteria = new Object(); | ||
| − | // Find | + | // Find the selected messages |
| − | for (var msgIndex = 0; msgIndex < | + | for (var msgIndex = 0; msgIndex < messageList.length; msgIndex++) { |
| − | if ( | + | if (messageList.options[msgIndex].selected) { |
| − | // Get message id of selected message | + | // Get message id of the selected message |
| − | var messageId = | + | var messageId = messageList.options[msgIndex].value; |
// Radix of message id integer value | // Radix of message id integer value | ||
var radix = 10; | var radix = 10; | ||
| Line 221: | Line 60: | ||
var result = serviceObject.IMessaging.Delete(criteria); | var result = serviceObject.IMessaging.Delete(criteria); | ||
if (result.ErrorCode !== 0) { | if (result.ErrorCode !== 0) { | ||
| + | alert("Error in deleting messages"); | ||
break; | break; | ||
} | } | ||
// Remove message record from selection list | // Remove message record from selection list | ||
| − | + | messageList.remove(msgIndex); | |
msgIndex = msgIndex - 1; | msgIndex = msgIndex - 1; | ||
} | } | ||
} | } | ||
getMessageList(); | getMessageList(); | ||
| − | |||
} | } | ||
</code> | </code> | ||
==Postconditions== | ==Postconditions== | ||
| − | + | ||
| − | + | The selected SMS or MMS messages are deleted. | |
| − | + | ||
| − | + | ||
| − | + | ||
==Supplementary material== | ==Supplementary material== | ||
| + | |||
You can view the source file and executable application in the attached ZIP archive. The archive is available for download at [[Media:Removing_message_from_Inbox_in_WRT.zip]]. | You can view the source file and executable application in the attached ZIP archive. The archive is available for download at [[Media:Removing_message_from_Inbox_in_WRT.zip]]. | ||
| + | |||
| + | ==See also== | ||
| + | |||
| + | * [[CS001246 - Listing inbox messages in WRT]] | ||
[[Category:Web Runtime (WRT)]][[Category:Code Examples]][[Category:Messaging]][[Category:S60 5th Edition]] | [[Category:Web Runtime (WRT)]][[Category:Code Examples]][[Category:Messaging]][[Category:S60 5th Edition]] | ||
Revision as of 10:23, 16 January 2009
Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 5th Edition
Article
Keywords: device.getServiceObject(), Service.Messaging.Delete()
Created: (18 Dec 2008)
Last edited: tapla
(16 Jan 2009)
Overview
This code snippet shows how to delete a message from the Inbox using the Messaging Platform Service for S60 Web Runtime, introduced in S60 5th Edition.
To obtain access to the service object for the Messaging Service API, the device.getServiceObject("Service.Messaging", "IMessaging") method is used.
Source
The HTML select component contains the messages:
<select size="5" id="messageList" multiple></select><br />var serviceObj = null;
// Initializes the widget
function init() {
try {
serviceObj = device.getServiceObject("Service.Messaging",
"IMessaging");
} catch (ex) {
alert("Service object cannot be found.");
return;
}
}
// Removes the message which is selected in the list box.
function removeMessage() {
// Get a reference to SELECT object which contains the list of messages
var messageList = document.getElementById("messageList");
var criteria = new Object();
// Find the selected messages
for (var msgIndex = 0; msgIndex < messageList.length; msgIndex++) {
if (messageList.options[msgIndex].selected) {
// Get message id of the selected message
var messageId = messageList.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) {
alert("Error in deleting messages");
break;
}
// Remove message record from selection list
messageList.remove(msgIndex);
msgIndex = msgIndex - 1;
}
}
getMessageList();
}
Postconditions
The selected SMS or MMS messages are deleted.
Supplementary material
You can view the source file and executable application in the attached ZIP archive. The archive is available for download at Media:Removing_message_from_Inbox_in_WRT.zip.

