Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using the Bridge Object to Retrieve a Single Record by Record ID
PRODUCT: 4D Web 2.0 Pack | VERSION: 11.2 | PLATFORM: Mac & Win
Published On: December 3, 2008
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

PLEASE NOTE: This Tech Tip applies to 4D Ajax Framework v11 Release 2

The Bridge is a 4D Ajax Framework component that enables direct communication between 4DAF front end objects and 4D. The Bridge's API allows you to query records from 4D, but sometimes it is more convenient to request a single record by record ID, if you already have that value on the front end.

One example of obtaining a record ID would be responding to the Data Grid object's onDataRowClick event, which passes recordId as a parameter to your handler JavaScript function. Inside the handler you could grab the recordId parameter and pass it in a getRecord Bridge call:

dax_bridge.getRecord(selectionName, recordId, handler, passedValue);

* selectionName is a table, view or DCS.
* recordId is a record ID number in the format [tableNum][recordNum].
* handler is a JavaScript function that's called after 4D response is received
* passedVariable (optional) is a custom Javascript object of your choosing or making that is passed to the handler function

Note: Only fields that are selected for Input in the 4DAF Admin Control Panel will be passed.
The handler function receives a parsed record data structure, so you must put (parsedRecord) as a parameter in the handler's function signature.

Here is an example of usage:

dax_bridge.getRecord('Department', '[2],[6]', myGetRecordHandler);

function myGetRecordHandler(parsedRecord) {
    //In the handler, get data for each field out of the parsedRecord data structure
    var deptidVal = parsedRecord[0].fields[0].value;
    var deptnameVal = parsedRecord[0].fields[1].value;
    var deptlocVal = parsedRecord[0].fields[2].value;
    var deptmgrVal = parsedRecord[0].fields[3].value;

Note that the parsedRecord object is an array of records, the same object type returned when doing a Bridge query. So even though you only asked for one record, you need to refer to the first element of the array, parsedRecord[0].

For more information see the Bridge 2.0 documentation in the Daxipedia: