/* subscribe to event */
dsCustomer.ttCustomer.subscribe('afterDelete', onAfterDelete); /* some code that deletes a record and sends it to the server */ var jsrecord = dsCustomer.ttCustomer.find(function(jsrecord) { return (jsrecord.data.Name === 'Lift Tours'); }); if (jsrecord) {jsrecord.remove();} /* some other JSDO memory record changes . . . */ dsCustomer.autoApplyChanges = false; dsCustomer.saveChanges(false).done( /* Successful method execution */ function( jsdo, success, request ) { /* all resource operations invoked by saveChanges() succeeded */ /* for example, track the average customer balance in certain states */ var avgBalance = { MA : 0.0, maCount : 0, VT : 0.0, vtCount : 0 }; jsdo.ttCustomer.foreach( function(jsrecord) { if (jsrecord.data.State === 'MA') { /* sum balances for customers in MA . . . */ avgBalance.MA += jsrecord.data.Balance; avgBalance.maCount += 1; } if (jsrecord.data.State === 'VT') { /* sum balances for customers in VT . . . */ avgBalance.VT += jsrecord.data.Balance; avgBalance.vtCount += 1; } }); /* compute averages and process further . . . */ avgBalances.MA = avgBalances.MA / avgBalances.maCount; avgBalances.VT = avgBalances.VT / avgBalances.vtCount; }).fail( /* Unsuccessful method execution */ function( jsdo, success, request ) { /* one or more resource operations invoked by saveChanges() failed */ var lenErrors, errors, errorType; /* handle all operation errors */ errors = jsdo.ttCustomer.getErrors(); lenErrors = errors.length; for (var idxError=0; idxError < lenErrors; idxError++) { /* Each error */ console.log(JSON.stringify(errors[idxError])); } }); function onAfterDelete (jsdo , record , success , request ) { /* check for errors on any Delete operation */ if (success) { /* do the normal thing for a successful Delete operation. for example, log the deleted record to the console */ console.log("Deleted Customer record for: " + record.data.Name); } record.acceptRowChanges(); } else { /* all error messages handled by the Promise.fail() callback */ record.rejectRowChanges(); } }; |
/* subscribe to event */
dsCustomer.ttCustomer.subscribe('afterDelete', onAfterDelete); /* some code that deletes a record and sends it to the server */ var jsrecord = dsCustomer.ttCustomer.find(function(jsrecord) { return (jsrecord.data.Name === 'Lift Tours'); }); if (jsrecord) {jsrecord.remove();}; /* some other JSDO memory record changes . . . */ dsCustomer.autoApplyChanges = false; dsCustomer.saveChanges(false).done( /* Successful method execution */ function( jsdo, success, request ) { /* all resource operations invoked by saveChanges() succeeded */ /* for example, track the average customer balance in certain states */ var avgBalance = { MA : 0.0, maCount : 0, VT : 0.0, vtCount : 0 }; jsdo.ttCustomer.foreach( function(jsrecord) { if (jsrecord.data.State === 'MA') { /* sum balances for customers in MA . . . */ avgBalance.MA += jsrecord.data.Balance; avgBalance.maCount += 1; } if (jsrecord.data.State === 'VT') { /* sum balances for customers in VT . . . */ avgBalance.VT += jsrecord.data.Balance; avgBalance.vtCount += 1; } }); /* compute averages and process further . . . */ avgBalances.MA = avgBalances.MA / avgBalances.maCount; avgBalances.VT = avgBalances.VT / avgBalances.vtCount; }).fail( /* Unsuccessful method execution */ function( jsdo, success, request ) { /* one or more resource operations invoked by saveChanges() failed */ var lenErrors, errors, errorType; /* handle all operation errors */ errors = jsdo.ttCustomer.getErrors(); lenErrors = errors.length; for (var idxError=0; idxError < lenErrors; idxError++) { /* Each error */ switch(errors[idxError].type) { case progress.data.JSDO.DATA_ERROR: errorType = "Server 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; case default: errorType = null; // Unexpected errorType value break; } if (errorType) { /* log all error text console.log("ERROR: " + errorType + errors[idxError].error); if (errors[idxError].id) { /* error with record object */ console.log("RECORD ID: " + errors[idxError].id); /* possibly log the data values for record with this ID */ } if (errors[idxError].responseText) { console.log("HTTP FULL TEXT: " + errors[idxError].responseText); } } else { /* unexpected errorType */ console.log("UNEXPECTED ERROR TYPE: " + errors[idxError].type); } } }); function onAfterDelete (jsdo , record , success , request ) { /* check for errors on any Delete operation */ if (success) { /* do the normal thing for a successful Delete operation. for example, log the deleted record to the console */ console.log("Deleted Customer record for: " + record.data.Name); } record.acceptRowChanges(); } else { /* all error messages handled by the Promise.fail() callback */ record.rejectRowChanges(); } }; |