Queries
The Platform AJAX Query API allows developers to run SQL SELECT queries from application and portal pages using AJAX.
The process of performing a SELECT query using the Client-Side Query API is similar to the server-side API described (see Server-side API).
AJAX Query API functions typically require a callback function as a parameter. This is due to the asynchronous nature of AJAX communications. You should process results inside that callback function rather than try to use global JavaScript variables. For complex processing consider using other functions inside callback, possibly included in the hosted files. For information on hosted files, see Hosted files.
Consider an example of invalid API usage:
var globalcount; rbf_selectNumber("SELECT COUNT(1) FROM USER", function(count) { globalcount = count; } ); alert("Counter="+globalcount);
The following code will display "Counter=undefined" since the processing of query result starts before that result is fetched. However this example will work as expected:
rbf_selectNumber("SELECT COUNT(1) FROM USER", function(count) { alert("Counter="+count); } );
Several Query API return results as JSON arrays or single values. JSON return values include those shown in the following table.
Data Type | JSON Value |
---|---|
NULL (no value)
|
null
|
Number
|
Number
|
Boolean value | true or false |
String
|
String
|
Relationship (lookup) | Array of related ids |
Date or Date/time |
Instance of JavaScript Date
class |