JSDO properties, methods, and events reference : findById( ) method
  

findById( ) method

Locates and returns the record in JSDO memory with the internal ID you specify.
If no record is found, it returns null. You can access the internal ID of the working record of a table reference, or any JSRecord object, by calling the getId( ) method on the object returned by the data property of the JSRecord.
Return type: progress.data.JSRecord class
Applies to: progress.data.JSDO class, table reference property (JSDO class)
Working record: After completing execution, any record found becomes the working record for the associated table. If the searched table has child tables in the same multi-table resource, and the useRelationships property is true, the working record of the result set for each child is set to the first record as determined by the relationship to its respective parent. If a record is not found, the working record is not set, and the working records of any child tables are also not set.

Syntax

jsdo-ref.findById ( id )
jsdo-ref.table-ref.findById ( id )
jsdo-ref
A reference to the JSDO. You can call the method on jsdo-ref if the JSDO has only a single table reference.
table-ref
A table reference on the JSDO.
id
The internal record ID used to match a record of the table reference. This is the same value originally returned for the record using the getId( ) function. It is typically used to create a jQuery listview row to display the record or a detail form used to display the record in the current HTML document. Later, when a listview row or detail form is selected, the corresponding id attribute with this value can be used to return the record from the JSDO, possibly to update the record with new data values input by the user.
If findById( ) locates a record with the matching record ID, it completes execution with both its return value and the record property of the table reference set to the JSRecord reference of the found working record. If the function does not locate the record, it completes execution with both its return value and the record property on the table reference set to null, indicating that no record of the table reference has a matching internal record ID.
If the table reference references a child table in a multi-table resource, when the useRelationships property is true, findById( ) uses the relationship to filter out all but the child records of the working record in the parent table; the remaining child records are excluded from the search. If useRelationships is false or the working record of the parent is not set, the search includes all records of the child table and no error is thrown.

Example

The following code fragment shows a jQuery event defined on a save button to save the current field values for a customer detail form to the corresponding eCustomer record in JSDO memory:
dataSet = new progress.data.JSDO( 'dsCustomerOrder' );

$('#btnSave').bind('click', function(event) {
  var jsrecord = dataSet.eCustomer.findById($('#custdetail #id').val());
  if (jsrecord) {jsrecord.assign();};
  dataSet.saveChanges();
});
The form has been displayed with previous values of the same record. When the button is clicked, the event handler finds the original eCustomer record by calling findById( ) with the id attribute of the form ($('#custdetail #id').val()), which is set to the internal ID of the record. The jsrecord.assign( ) method then updates the record from the values of the corresponding form fields and saveChanges( ) invokes the resource "update" operation on the AppServer to save the updated record to its data source.

See also:

data property, foreach( ) method, getId( ) method