Would someone be able to provide an example of the best way to load data from a Rollbase object into the KendoUI datasource so that it's usable within a widget? The specific example we're trying to build out is to use the TreeList widget to show records related to an object. Is this best done through the browser API or is there a better way?
Thanks in advance for your help!
Example to generate JSON content within the trigger (list of contacts):
var country = "Netherlands"; var myArray = new Array(); var resultSet = rbv_api.selectQuery("SELECT firstName, lastName, country from customer WHERE country = ?", 1000, country) for (int idx =0; i< resultSet.length; i++){ myArray.push({"firstName": resultSet[i][0], "lastName": resultSet[i][1], "country": resultSet[i][2]}); } var myStringifiedJSON = rbv_api.jsonToString(myArray); return myStringifiedJSON;
)
An approach would be to create a JSON object of the data you aim to pass to the widget, serialize it as a string and store it in a text field using either
- JSON.stringify(myArray)
or
- rbv_api.jsonToString(myArray)
(both methods do the same thing)
You can implement this logic in a trigger
The second step is to add your Widget code in a page inside a "Script component" in which you will also retrieve the field value storing the stringified JSON, and perform the inverse operation:
var datasource = JSON.parse('{!myStringifiedJSON}');
or
var datasource = rbv_api.stringToJson('{!myStringifiedJSON}')
You have now a datasource as a javascript array which you can pass to your widget.
Example to generate JSON content within the trigger (list of contacts):
var country = "Netherlands"; var myArray = new Array(); var resultSet = rbv_api.selectQuery("SELECT firstName, lastName, country from customer WHERE country = ?", 1000, country) for (int idx =0; i< resultSet.length; i++){ myArray.push({"firstName": resultSet[i][0], "lastName": resultSet[i][1], "country": resultSet[i][2]}); } var myStringifiedJSON = rbv_api.jsonToString(myArray); return myStringifiedJSON;
)
.