afterDelete event

Fires after the JSDO, by means of a saveChanges( ) call following a remove( ) call, sends a request to delete a record in the Data Object resource and receives a response to this request from the server.

This event fires after the response from a Delete operation request (sent without using Submit) has been received, and fires after the response from a Submit operation request for each one of possibly multiple record deletes has been received.

Note: A single Delete operation request is sent for each record object that you have deleted in the JSDO with a single call to saveChanges( ) or saveChanges(false). A single Submit operation request for any and all created, updated, and deleted JSDO record objects is sent with a single call to saveChanges(true).

Applies to: progress.data.JSDO class, table reference property (JSDO class)

The following parameters appear in the signature of any event handler (callback) function (or functions) that you subscribe to this event:

Syntax

function ( jsdo , record , success , request )
jsdo
A reference to the JSDO that invoked the delete request. For more information, see the description of jsdo property of the request object.
record
A reference to the table record upon which the delete request acted. For more information, see the description of jsrecord property of the request object.
success
A boolean that is true if the delete request was successful. For more information, see the description of success property of the request object.
request
A reference to the request object returned after the delete request completes. For more information, see the description of request object.

Application code can subscribe a callback to this event by invoking the subscribe( ) method on a JSDO instance or one of its table references.

Example

The following code fragment subscribes the function, onAfterDelete, to handle the afterDelete event fired on the JSDO, myjsdo, created for a single-table resource, ttCustomer, where myid is the known ID of a record to find and delete:

/* subscribe to event */
myjsdo.subscribe( 'afterDelete', onAfterDelete );

/* some code that might delete one or more 
   records, then remove them on the server */
var jsrecord = myjsdo.findById(myid);
if (jsrecord) {jsrecord.remove();};
. . .

myjsdo.saveChanges();

function onAfterDelete ( jsdo , record , success , request ) {
    var myField, 
        lenErrors, 
        errors,
        errorType;
    if (success) {
        /* for example, get the values from the record that was 
           deleted to display a confirmation message */
        myKeyField = record.data.myKeyField;
        . . .
    }
    else { /* Handle Delete operation errors */
        errors = jsdo.ttCustomer.getErrors();
        lenErrors = errors.length;
        for (var idxError=0; idxError < lenErrors; idxError++) {
            switch(errors[idxError].type) {
                case progress.data.JSDO.DATA_ERROR:
                    errorType = "BI Data Error: ";
                    break;
                case progress.data.JSDO.RETVAL:
                    errorType = "Server App Return Value: ";
                    break;
                case progress.data.JSDO.APP_ERROR:
                    errorType = "Server App Error #" 
                                  + errors[idxError].errorNum + ": ";
                    break;
                case progress.data.JSDO.ERROR:
                    errorType = "Server General Error: ";
                    break;
            }
            /* Log error type and message for current error */
            console.log("ERROR: " + errorType + errors[idxError].error);
            if (errors[idxError].id) { /* Log info for error with record object */
                console.log("RECORD ID: " + errors[idxError].id);
                /* If the error record ID matches the operation 
                   record ID, log the record data values */
                if  (errors[idxError].id == record.getId()) {
                    console.log ("Customer Record Fields:");
                    console log ("    CustNum = " + record.data.CustNum);
                    . . .
                }
            }
            /* Log additional HTTP text for web or other server errors */
            if (errors[idxError].responseText) {
                console.log("HTTP FULL TEXT: " + errors[idxError].responseText);
            }
        }
    } /* End Delete operation errors */
};

See also:

beforeDelete event, remove( ) method, saveChanges( ) method, subscribe( ) method (JSDO class), unsubscribe( ) method (JSDO class)