# Create a foundset from a dataset

**URL:** <https://forum.servoy.com/t/create-a-foundset-from-a-dataset/15372>\
**Category:** Classic Servoy\
**Created:** [January 18, 2012, 9:21am UTC](https://forum.servoy.com/t/create-a-foundset-from-a-dataset/15372 "2012-01-18T09:21:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasantana](https://avatars.discourse-cdn.com/v4/letter/j/e79b87/32.png) [@jasantana](https://forum.servoy.com/u/jasantana)\
**Post date:** [January 18, 2012, 9:21am UTC](https://forum.servoy.com/t/create-a-foundset-from-a-dataset/15372/1 "2012-01-18T09:21:35Z")

</div>

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:

```auto
var apptsDS = databaseManager.getDataSetByQuery(globals.calSrvName, 'SELECT * FROM appointments', null, 0);

```

Then I fill information I need and create the foundset:

```auto
var availabilityDS = apptsDS.createDataSource('availability');
/** @type {JSFoundset<db:/saascalendar/appointments>} */
var availabilityFS = databaseManager.getFoundSet(availabilityDS);
return availabilityFS;

```

Thanks.

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [January 18, 2012, 5:00pm UTC](https://forum.servoy.com/t/create-a-foundset-from-a-dataset/15372/2 "2012-01-18T17:00:44Z")

</div>

> 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?

---

<div class="post-metadata">

**Author:** ![jasantana](https://avatars.discourse-cdn.com/v4/letter/j/e79b87/32.png) [@jasantana](https://forum.servoy.com/u/jasantana)\
**Post date:** [January 18, 2012, 5:11pm UTC](https://forum.servoy.com/t/create-a-foundset-from-a-dataset/15372/3 "2012-01-18T17:11:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [January 19, 2012, 10:00am UTC](https://forum.servoy.com/t/create-a-foundset-from-a-dataset/15372/4 "2012-01-19T10:00:44Z")

</div>

please give use more code examples, how do you get myFoundset?  
It seems that that is not typed correctly.

---

<div class="post-metadata">

**Author:** ![jasantana](https://avatars.discourse-cdn.com/v4/letter/j/e79b87/32.png) [@jasantana](https://forum.servoy.com/u/jasantana)\
**Post date:** [January 27, 2012, 11:39am UTC](https://forum.servoy.com/t/create-a-foundset-from-a-dataset/15372/5 "2012-01-27T11:39:14Z")

</div>

Sorry Johan I´ve been busy trying to finish some other things.

Here is the code to get the dataSource:

```auto
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:

```auto
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()

---

<div class="post-metadata">

**Author:** ![jasantana](https://avatars.discourse-cdn.com/v4/letter/j/e79b87/32.png) [@jasantana](https://forum.servoy.com/u/jasantana)\
**Post date:** [January 27, 2012, 12:07pm UTC](https://forum.servoy.com/t/create-a-foundset-from-a-dataset/15372/6 "2012-01-27T12:07:51Z")

</div>

I got it working. I have changed the retrieveAppointments() function as:

```auto
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.
