Using JSDOs to create mobile and web clients : Accessing standard CRUD and Submit operations : Delete operation example
  

Delete operation example

To delete an existing record from JSDO memory on the client, you call the remove( ) method on a JSDO table reference.
You can call the remove( ) method on:
*A table reference on the JSDO that has a working record
*A specific progress.data.JSRecord object reference, as in the example below
When the remove( ) method completes, no working record is set for the associated table or any of its child tables.
After either a successful call to the remove( ) method, the JSDO marks the affected record for pending deletion on the server.
To synchronize the server database with existing records you have deleted in JSDO memory without using a Submit operation, you call saveChanges( ) by passing either an empty parameter list to the method or a single parameter value of false. This executes the OpenEdge ABL or Rollbase server routine that implements the Data Object Update operation once for each deleted record in JSDO memory. In addition, for any other changed records in JSDO memory, this call also executes the server routine that implements the associated Create or Update operation once for each associated record change.
Note: When multiple pending record changes exist in JSDO memory, the saveChanges( ) method invoked without Submit groups invocation of the associated resource operations in the order of 1) all Delete operations, 2) all Create operations, and 3) all Update operations, and invokes each such operation one record at a time over the network.
When you call the saveChanges( ) method, if jQuery Promises are supported in your environment, it returns a Promise object on which you can register callbacks to handle completion of all record-change operations that it has invoked. Otherwise, you can subscribe event callbacks to handle the results of these operations.
Operation results are thus returned as follows:
1. For each Delete operation that completes, the JSDO fires an afterDelete event to execute any callbacks you have subscribed to handle that event. The JSDO also fires any afterCreate and afterUpdate events to execute callbacks you have subscribed to handle these events.
2. After all record-change operations complete, the JSDO fires an afterSaveChanges event to execute any callbacks you have subscribed to handle that event. In addition, any returned Promise object executes the Promise callbacks that you have registered, depending on the combined operation results. (Note that the signatures of all Promise callbacks are identical to the signature of the afterSaveChanges event callback.)
After the saveChanges( ) method and all resource operations that it has invoked successfully complete, no working records are set for the tables in the JSDO.
Note: If an error occurs on the server, and the autoApplyChanges property has the default value of true, any deleted record is restored to JSDO memory on the client.
For more information on handling saveChanges( ) method results for individual record-change operations, see the description of the saveChanges( ) method.
Following is an example showing an OpenEdge ABL implementation of the Delete operation and its invocation on a JSDO.
Note: The bold code in the JavaScript examples primarily trace the path of referenced JSDO method and callback parameters, as well as key code elements in the example, including those elements that are directly or indirectly referenced in the example description and notes.
* An OpenEdge ABL implementation for Delete
* Client JavaScript code: Delete