OpenEdge Development: Mobile Applications - Product ...
OpenEdge Development: Mobile Applications - Product ...
OpenEdge Development: Mobile Applications - Product ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Client JavaScript code: Update<br />
Accessing built-in CRUD operations<br />
The following example illustrates calling assign( ) on a table reference in the JSDO<br />
to update a record:<br />
/* subscribe to event */<br />
dsOrderEntry.subscribe('afterUpdate', onAfterUpdate);<br />
var updatedDataObject = {City: 'Nashua'};<br />
/* some code that would update a record and send it to the server */<br />
var jsrecord = dsOrderEntry.ttCustomer.findById(myid);<br />
dsOrderEntry.ttCustomer.assign( updatedDataObject );<br />
dsOrderEntry.saveChanges();<br />
function onAfterUpdate (jsdo , record , success , request ) {<br />
if (success) {<br />
/* for example, get the values updated by the server from the record<br />
to redisplay */<br />
var newValue = record.data.myField;<br />
<br />
}<br />
else {<br />
if (request.response && request.response._errors &&<br />
request.response._errors.length > 0){<br />
var lenErrors = request.response._errors.length;<br />
for (var idxError=0; idxError < lenErrors; idxError++) {<br />
var errorEntry = request.response._errors[idxError];<br />
var errorMsg = errorEntry._errorMsg;<br />
var errorNum = errorEntry._errorNum;<br />
/* handle error */<br />
}<br />
}<br />
}<br />
}<br />
Notice that the sample code:<br />
• Subscribes an event-handler function, onAfterUpdate, to the afterUpdate event<br />
to enable error-checking and manipulation of the revised record.<br />
• Calls findById( ) to retrieve the record to be updated, which becomes the<br />
working record for the ttCustomer table, and changes the value of the City field<br />
to Nashua. (The table reference could be omitted if ttCustomer were the only<br />
temp-table in the dsOrderEntry ProDataSet.)<br />
• Calls saveChanges( ) to execute UpdateOrderEntry( ) on the AppServer and<br />
thereby synchronize the content of local storage with the database.<br />
Delete operation<br />
To delete an existing record from local storage on the client, you call the remove( )<br />
method.<br />
The remove( ) method can be called on either of the following:<br />
• A table reference on the JSDO. When called on a table reference, assign( )<br />
operates on the working record for that table.<br />
• A specific JSRecord object. The example below uses this technique.<br />
<strong>OpenEdge</strong> ® <strong>Development</strong>: <strong>Mobile</strong> <strong>Applications</strong> 111