6.4.3 Delete

Delete is used to delete one or more contacts or contact groups from a contact database. It deletes data from a specified database or from the default database if you do not specify a database. This method can be called both in synchronous and asynchronous mode.

The following is an example for using Delete:

Asynchronous

event_id = contacts_handle.call('Delete', {'Type': u'Contact', 'Data': {'IdList': [req_id]}}, callback=del_contact)

where, del_contact is a user defined callback function.

The following table summarizes the specification of Delete:

Interface IDataSource
Operation Deletes an array of contacts/groups from the specified or default contacts database.
Response Model Asynchronous and synchronous for Third Edition FP2 and Fifth Edition devices.
Synchronous for Third Edition and Third Edition FP1 devices.
Pre-condition IDataSource interface is loaded. Contact must exist in the contacts database. The IDs can be obtained from GetList.
Post-condition Nil

Input Parameters

The following table describes input parameter. The default contacts database is cntdb://c:contacts.cdb. The SIM card database is sim://global_adn. The contacts or contacts groups to be deleted must exist in the specified database. You must use GetList to retrieve the IDs of the entries you want to delete.

Table 6.70: Input parameters for Delete
Name Type Range Description
Type unicode string Contact
Group
Operation is performed on the specified type.
Data Contact or Group (map)
[DBUri]: unicode string
IdList: List
[id1, id2, id3]
All string values in the map are unicode. IdList is a mandatory field. You must specify the contact ids or group ids to delete a set of contacts/groups from the contacts database given by the list. For example, id1, id2, id3 are the ids of the contacts/groups.

DBUri is optional, it operates on the specified database or on the default database, if specified.


Output Parameters

The output is an object, which contains ErrorCode and an ErrorMessage if the operation fails.

Table 6.71: Output parameters for Delete
Name Type Range Description
ErrorCode int NA Contains the SAPI specific error code when the operation fails and SErrNone on success.
ErrorMessage string NA Error Description in Engineering English.


Errors

The following table lists the errors and their values:

Table 6.72: Error codes
Error code value Description
0 Success
1002 Bad argument type
1004 Service not supported
1005 Service in use
1011 Access denied


Error Messages

The following table lists the error messages and their description:

Table 6.73: Error messages
Error messages Description
Contacts:Delete:Type is missing Indicates Type is missing
Contacts:Delete:Invalid Type, must be Contact/Group Indicates invalid value for Type, if it is not Contact or Group.
Contacts:Delete:Delete data Missing Indicates that the key Data is missing.
Contacts:Delete:Invalid Type of Data, Map is required Indicates that the value of the Data is not present and Map is expected.
Contacts:Delete:List of Ids is Missing Indicates that the list of Contact Ids to be deleted is missing.
Contacts:Delete:Type of IdList is wrong, List is required Indicates that value of IdList is not a List.
Contacts:Delete:Invalid Type of Id Indicates that Contact/Group Id is not a string.
Contacts:Delete:Wrong Type of ContentType Indicates that the value for Type is not a string.
Contacts:Delete:Mandatory Argument is not present Indicates that Type is not a string.


Example

The following sample code illustrates how to delete a contact:

import scriptext
import e32

# Using e32.Ao_lock() to make main function wait till callback is hit
lock = e32.Ao_lock()

# Callback function will be called when the requested service is complete
def del_contact(trans_id, event_id, input_params):
    if event_id != scriptext.EventCompleted:   
# Check the event status
        print "Error in deleting the contact"
        print "Error code is: " + str(input_params["ReturnValue"]["ErrorCode"])
        if "ErrorMessage" in input_params["ReturnValue"]:
           print "Error message:" + input_params["ReturnValue"]["ErrorMessage"]
    else:
        print "The contact is deleted"
        lock.signal()

# Load contacts module
contacts_handle = scriptext.load("Service.Contact", "IDataSource")

list_contacts = contacts_handle.call('GetList', {'Type': u'Contact', 'Filter': {'SearchVal': u'Paulo'}})
for i in list_contacts:
     req_id = i['id']

event_id = contacts_handle.call('Delete', {'Type': u'Contact', 'Data':{'IdList': [req_id]}}, callback=del_contact)

print "Waiting for the request to be processed!"
lock.wait()
print "Request complete!"

See About this document... for information on suggesting changes.