namedFoundSet in SolutionModel

FormA has tab panel1 that contains form1 and tab panel 2 that contains form 2. All forms have the same data source.
I want form1 and form2 both with separate found sets.

var formCal1 = solutionModel.newForm('cal1', 'coperta', 'actions', null, true, 240, 35);
	var headerCal1 = formCal1.newHeaderPart(20)
	formCal1.navigator = SM_DEFAULTS.NONE;
	formCal1.scrollbars = SM_SCROLLBAR.HORIZONTAL_SCROLLBAR_NEVER|SM_SCROLLBAR.VERTICAL_SCROLLBAR_NEVER;
	formCal1.borderType = 'EmptyBorder,0,0,0,0'
	formCal1.styleName = 'coperta';
	formCal1.styleClass = 'toolbar';
	formCal1.transparent = true;
	formCal1.view = JSForm.LIST_VIEW

	formCal1.onLoad = formCal1.newFormMethod('function onShow() {var frm = currentcontroller.getName();forms["cal1"].controller.loadAllRecords();var query = "SELECT usr_id FROM users WHERE usr_cal_user =1";var dataset = databaseManager.getDataSetByQuery(currentcontroller.getServerName(), query, null, 100); var vdataset = dataset; var row = new Array();forms["cal1"].controller.find(); var rangeX = "#" + globals.g_search_day_1 + "|dd-MM-yyyy"; var first = vdataset.getValue(1, 1); forms["cal1"].act_user_id = first; forms["cal1"].act_date_begin = rangeX; forms["cal1"].act_type = "2"; for(var i = 2 ; i <= dataset.getMaxRowIndex() ; i++ ){row[i] = vdataset.getValue(i, 1); forms["cal1"].controller.newRecord(); forms["cal1"].act_user_id = row[i]; forms["cal1"].act_date_begin = rangeX; forms["cal1"].act_type = "2";}forms["cal1"].controller.search();}')	

	var myFoundSet1 = forms['cal1'].foundset;
	//formCal1.namedFoundSet = myFoundSet1;

As soon as I call “formCal1.namedFoundSet = myFoundSet1;” it comes with a “Stale form error”

Thanks for any help

I think that the namedFoundSet property only tells if the foundset is separate, not what foundset is used in the form. Did you try formCal1.namedFoundSet = “separate”?

Hello Victor,

Did you try formCal1.namedFoundSet = “separate”?

Yes I’ve tried that, but it doesn’t work.

According the sample that comes with the method it is necessary to define a found set first an then give the name to the property.

var firstForm = solutionModel.newForm('newForm1', 'myServer', 'myTable', null, true, 800, 600);
	var secondForm = solutionModel.newForm('newForm2', 'myServer', 'myTable', null, true, 800, 600);
	forms['newForm2'].controller.find()
	forms['newForm2'].columnTextDataProvider = '=aSearchValue';
	forms['newForm2'].controller.search()
	var myFoundSet = forms['newForm2'].foundset
	firstForm.namedFoundSet = myFoundSet;

The mistake must be somewhere else… no idea where :(

Seeing the wiki http://wiki.servoy.com/display/public/DOCS/JSForm#JSForm-namedFoundSet :

Property that tells the form to use a named foundset instead of the default foundset.
When “separate” as special value is specified the form will always create a copy of assigned foundset and therefor become separated from other foundsets

and in the property tooltip info in the developer:

String namedFoundSet Property that tells the form to use a named foundset instead of the default foundset. Currently only “separate” can be specified as value, meaning that the form will use a separate foundset.

I think that the sample is wrong… Can any Servoyan confirm this?

This is right for a physical form but my forms are designed with the SolutionModel.

If I try formCal1.namedFoundSet = “separate” it returns the same “Stale form” error and if I try separate without quotes it complains that separate is not defined.

I wish it were just so simple.

That’s because you call ’ var myFoundSet1 = forms[‘cal1’].foundset;’
Asking for the foundset of a form simply loads the form in memory.
After that you’re trying to alter the form again by setting the ‘namedFoundset’ property.

As for the namedFoundset property: as far as I know the solutionModel can not handle any other settings than the normal form properties.

Hello Marc,

Thanks for the explanation.

But how can I tell to the form to use a different found set If I have made it with the SolutionModel?
With the physical Form you just put "separate in the property an the trick is done. But the Solution Model doesn’t allow that.

based on a designtime form I’d say: jsForm.namedFoundSet = ‘separate’ should do the job.
after that you can load just any foundset you want, without this forms foundset will alter another foundset based on the same table.

I wish… as I already wrote:

If I try formCal1.namedFoundSet = “separate” it returns the same “Stale form” error and if I try separate without quotes it complains that separate is not defined.

I wish it were just so simple.

Thats why I don’t get it, in the physical forms is so simple… may be a bug?

the “Stale form” error is thrown when you alter a form that’s already in memory.

when you reference ‘forms[‘justAnyFormName’]’ this form is being loaded into memory.
After that no alterations can be made to that form using the solutionModel as they will result in the “Stale form” error

So: move/delete the line where you reference ‘forms[‘cal1’].foundset’ (Based on your first post I’d say it has no use anymore) and you’re set.

Yeah, I forgot that. Now it works

Thank you.