6.4.5 Export

Export is used to export a contact from a contacts database. The information is exported to a vCard file. This API can be called both in synchronous and asynchronous mode.

The following is an example for using Export:

Asynchronous

event_id = contacts_handle.call('Export', {'Type': u'Contact','Data': {'DestinationFile': u'c:\\Data\\python\\contactlist.vcf', 'id': unicode(req_id)}}, callback=export_contact)

where, export_contact is a user defined callback function.

The following table summarizes the specification of Export:

Interface IDataSource
Operation Exports the selected item from the contacts database specified as VCard.
Response Model Asynchronous and synchronous for Third Edition FP2 and Fifth Edition devices.
Synchronous for Third Edition and Third Edition FP1 devices.
Pre-condition Valid IDataSource interface is loaded.
Valid contact store must exist.
The specified contact ID, retrieved using GetList, must be available.
Post-condition Exports contact to the specified file and creates a file in the specified location.

Input Parameters

The following table describes input parameter properties:

Table 6.78: Input parameters Export
Name Type Range Description
Type unicode string Contact Operation is performed on the specified type.
Data map
[DBUri]: unicode string
DestinationFile: unicode string
id: unicode string
All string values in the map are unicode.

Note:
DestinationFile can have any extension or no extension, usually it is .vcf
DestinationFile is of Vcard format.

Example of vcard formatis given below


If complete path is not specified, the file is created in private folder of the process.

DBUri: Exports contact from the specified database or to the default database if not specified.

DestinationFile: Exports contact to the specified file. It cannot be greater than 256 characters.

id: Exports the contact item with the specified id.


BEGIN:VCARD
VERSION:2.1
N:Kent; Clark
FN:Clark Kent
ORG:Superman Inc.
TITLE:Super Man
TEL;WORK:VOICE:(111) 556-9898
TEL;HOME;VOICE:(090) 556-6767
ADR;WORK:;;3rd Rock from Sun;Solar System;Milky Way
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:3rd Rock from Sun=0D=0ASolar System=0D=0AMilky Way
ADR;HOME:;;Krypton
LABEL;HOME;ENCODING=QUOTED-PRINTABLE:Krypton
EMAIL;PREF;INTERNET:clarkkent@krypton.com
REV:2008042T195243Z
END:VCARD

Output Parameters

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

Table 6.79: Output parameters for Export
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.80: Error codes
Error code value Description
1002 Bad argument type
1010 Entry exists
1012 Item not found


Error Messages

The following table lists the error messages and their description:

Table 6.81: Error messages
Error messages Description
Contacts:Export:Type is missing Indicates Type is missing
Contacts:Export:Invalid Type, it must be Contact Indicates invalid value for Type, it can be only Contact.
Contacts:Export:Export data Missing Indicates that the key Data is missing.
Contacts:Export:Invalid Type of Data, Map is required Indicates that the value of the Data is not a Map.
Contacts:Export:Export Destination Filename is Missing Indicates the argument to signify the filename to which contact is to be exported is missing.
Contacts:Export:Contact Id to be exported is missing Indicates that the id of the contact to be exported is missing.
Contacts:Export:Wrong Type of ContentType Indicates that the value for Type is not a string.
Contacts:Export:Destination Filename is of wrong Type Indicates that the filename is not a string.
Contacts:Export:Id is of wrong Type Indicates that the id is not a string.
Contacts:Export:Mandatory Argument is not present Indicates that not all mandatory arguments are present.
Contacts:Export:Export DataBaseUri is not a String Indicates that the uri specified is not a string.
Contacts:Export:Filename too long Indicates that filename has exceeded 256 characters.


Example

The following sample code illustrates how to export contacts to a file in VCard format:

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 export_contact(trans_id, event_id, input_params):
    if event_id != scriptext.EventCompleted:   # Check the event status
        print "Error in retrieving required info"
        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 exported"
        lock.signal()

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

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

event_id = contacts_handle.call('Export', {'Type': u'Contact', 'Data': {'DestinationFile': u'c:\\Data\\python\\contactlist.vcf', 'id': unicode(req_id)}}, callback=export_contact)

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

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