6.1.5 Cancelling of Asynchronous Service Request

To cancel an asynchronous request, Cancel is passed as the operation argument in the call() API. The transactionID associated with the asynchronous operation also needs to be passed. After completing the cancel operation, the callback function is called with Event_id as scriptext.EvenCanceled.

Syntax

serviceInstance.call('Cancel', {'TransactionID': serviceTransactionID})

where, transactionID is associated with the asynchronous operation, which needs to be cancelled.

Example

The following sample code illustrates how to send and cancel an SMS in asynchronous mode:

import scriptext
messaging_handle = scriptext.load('Service.Messaging', 'IMessaging')

def sms_send_callback(trans_id, event_id, output_params):
    if sms_trans_id == trans_id:
        if event_id == scriptext.EventCanceled:
            print "SMS Send Canceled"
        else:
            print "Event_id was not scriptext.EventCanceled"
    else:
        print "Invalid transaction ID received"

sms_trans_id = messaging_handle.call('Send', {'MessageType': u'SMS', 
                                              'To': u'12345678', 'BodyText': u'Hi'}, 
                                     callback=sms_send_callback)
try:
    messaging_handle.call('Cancel', {'TransactionID': sms_trans_id})
except scriptext.ScriptextError, err:
    print "Error cancelling request ", err

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