OpenEdge Development: Mobile Applications - Product ...
OpenEdge Development: Mobile Applications - Product ...
OpenEdge Development: Mobile Applications - Product ...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Client JavaScript code: Create<br />
Accessing built-in CRUD operations<br />
The following example illustrates calling add( ) on a table reference in the JSDO to<br />
create a record:<br />
/* subscribe to event */<br />
dsOrderEntry.ttCustomer.subscribe('afterCreate', onAfterCreate);<br />
/* some code that would add a record and save it */<br />
var jsrecord = dsOrderEntry.ttCustomer.add( {State : 'MA'} );<br />
<br />
dsOrderEntry.saveChanges();<br />
function onAfterCreate (jsdo , record , success , request ) {<br />
if (success) {<br />
/* for example, get the values from the record for redisplaying */<br />
var myField = 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, onAfterCreate, to the afterCreate event<br />
to enable error-checking and manipulation of the new record.<br />
• Adds the record to the ttCustomer table, with an initial value of MA for the State<br />
field. (The table reference could be omitted if ttCustomer were the only<br />
temp-table in the dsOrderEntry ProDataSet.)<br />
• Calls saveChanges( ) to execute CreateOrderEntry( ) on the AppServer and<br />
thereby synchronize the content of local storage with the database.<br />
Update operation<br />
To modify an existing record in local storage on the client, you call the assign( )<br />
method. The values of fields to be updated are specified in an object passed to the<br />
method.<br />
The assign( ) method can be called on either of the following:<br />
• A table reference on the JSDO. When called on a table reference, as in the<br />
example below, assign( ) operates on the working record for that table.<br />
• A specific JSRecord object.<br />
<strong>OpenEdge</strong> ® <strong>Development</strong>: <strong>Mobile</strong> <strong>Applications</strong> 109