Good morning !!
I need to create a foundset from a dataset. What I´m doing is first create the dataset with a getDataSetByQuery() and returning no records so I have a DS with the table structure. After that I fill the dataset with the calculated information, then create a dataSource from the dataSet and finally create a foundset from the dataSource.
What I need to get is a foundset with the free slots in a calendar. I have to read the google calendar and create a temporary foundset with the free slots.
The big problem is that I have no errors but I cannot access the foundset methods and properties.
Any idea on how to get this done or a better way to do it?
Here is the code I´m using:
I create the dataset:
var apptsDS = databaseManager.getDataSetByQuery(globals.calSrvName, 'SELECT * FROM appointments', null, 0);
Then I fill information I need and create the foundset:
var availabilityDS = apptsDS.createDataSource('availability');
/** @type {JSFoundset<db:/saascalendar/appointments>} */
var availabilityFS = databaseManager.getFoundSet(availabilityDS);
return availabilityFS;
Thanks.
The big problem is that I have no errors but I cannot access the foundset methods and properties.
what do you mean with this?
how and where can’t you access them?
The reason I need a foundset is because that foundset is passed to a global method that loops on it and creates labels. As I want to reuse that code I prefer sending a foundset otherwise I would have to rewrite it to read data from a dataset.
Just in the line: for(var i=1;i<=myFoundset.getSize(); i++) I get an error becuase getSize() is undefined.
I put a breakpoint before returning the foundset to check it with the debugger and I have the same result.
Version is 6.0.4
please give use more code examples, how do you get myFoundset?
It seems that that is not typed correctly.
Sorry Johan I´ve been busy trying to finish some other things.
Here is the code to get the dataSource:
function retrieveAppointments() {
var aArgs = new Array();
aArgs.push(globals.currentFirstDay);
aArgs.push(globals.currentLastDay);
//aArgs.push(globals.calTenantID);
var SQL = "SELECT CAST('Group '||appointments.tenantid AS character varying(100)) AS group_name, ";
SQL = SQL + " appointments.* FROM appointments ";
SQL = SQL + "WHERE appointments.start_datetime>=? AND appointments.end_datetime <=? ";
var _ds = databaseManager.getDataSetByQuery(globals.calSrvName, SQL, aArgs, -1);
if (_ds.getMaxRowIndex() > 0) {
return _ds.createDataSource('__appts');
} else {
return null;
}
}
And here part of the code in the function that calls the retrieveAppointments() and handles the returned dataSource:
function drawMonthAppointments() {
drawMonthCalendar();
// Retrieve the appointments.
apptsFS = retrieveAppointments();
if (apptsFS != null) {
var oldDay = null;
var lblSeeMore = null;
var oldWeek = null;
var nRepetition = 0;
var nWeek = 0;
for (var nAppts = 1; nAppts <= apptsFS.getSize(); nAppts++) {
apptsFS.setSelectedIndex(nAppts);
I get the error when checking the apptsFS.getSize()
I got it working. I have changed the retrieveAppointments() function as:
function retrieveAppointments() {
var aArgs = new Array();
aArgs.push(globals.currentFirstDay);
aArgs.push(globals.currentLastDay);
//aArgs.push(globals.calTenantID);
var SQL = "SELECT CAST('Group '||appointments.tenantid AS character varying(100)) AS group_name, ";
SQL = SQL + " appointments.* FROM appointments ";
SQL = SQL + "WHERE appointments.start_datetime>=? AND appointments.end_datetime <=? ";
var _ds = databaseManager.createDataSourceByQuery('__appts', globals.calSrvName, SQL, aArgs, -1);
if (_ds) {
var _fs = databaseManager.getFoundSet(_ds);
_fs.loadAllRecords();
if (_fs.getSize() > 0) {
return _fs;
}
}
return null;
}
Now it works. The big problem I think was that I thought that after creating the foundset it retrieved all the records, but it didn´t.
Anyway if you think this code could be better, please let me know.
Thanks.