controller.loadRecords() method is used to load records to a form’s foundset.
This TIP will make you familiar with different flavors/ways of loading records by using controller.loadRecords() method.
controller.loadRecords() can be used in Three different flavors/ways. The syntax of the method is :
controller.loadRecords([foundset/pkdataset/query], [queryArgumentsArray])
You can load records to the foundset by passing a foundset(must be a related one), dataset or simply a SQL Query. Servoy will load the records accordingly.
Loading Records from a Foundset
You can load records by passing an foundset object as the first argument to the controller.loadRecords() method. The Foundset must be a related one, on the form, on which you are loading records. For example, let say, your form based on the ‘projects’ table and you want to the load all the projects that the current logged in user is related to. You can do that, just by passing the relation to the controller.loadRecords() method of the form based on ‘projects’ table.
// load all the related projects that the current user related to
controller.loadRecords(g_current_user_projects);
Loading Records from a Dataset
You can load records by passing a Dataset containing all the PKs to the controller.loadRecords() method.
// set up the SQL Query for selecting all the projects // ordered by project title var _query = "SELECT projects.project_id FROM projects \
ORDER BY projects.project_title ASC";
// execute the query; get the PKs var _dataset = databaseManager.getDataSetByQuery(controller.getServerName()
, _query, null, 10000);
// load records according to the dataset
controller.loadRecords(_dataset);
Loading Records from a Query
You can load record by directly passing a SQL Query to the controller.loadRecords() method. You can even pass the parameters for your SQL Query as an argument.
Servoy will load the records according to the result of the SQL Query.
// get current date-time stamp
var _curDateTime = application.getServerTimeStamp();
// set up a SQL Query var _query = “SELECT projects.project_id FROM projects \
WHERE projects.due_on