JSDataSet.performUpdate is clearing my foundset

Running a method that uses JSDataSet.performUpdate to update a foundset for a form that is viewed as a form in dialog causes the foundset to clear, but in an odd way. The current record is still visible, but if I go to the next record, the controller looks like I am stepping through records, but I see only blank columns. Other forms using the same table show no records, even forms with ‘Use Separate Found Set’ checked. Once this happens, it only gets wierder. Loading records from a dataset derived from a SQL query produces found records, but no selected record. In this state, for some reason, methods are unable to resolve global relationships. I built a sample solution and the sample works fine, so I still have more troubleshooting to do. I wanted to post this now to see if anyone has any helpful input before I spend any more time on this.

Thanks in advance,
Steve in LA

What if you refresh the records after the update?

What do you mean by refresh the records? The form is in a Form In Dialog, so normal menu commands are not available. I also have the form’s default commands all set to none anyway. I tried them all set to Default, and it makes no difference.

Here is another piece of the puzzle: if I look at the form that is to be used in the Form In Dialog first, then go to the form that has the 'Detail" button that calls up the Form in Dialog, then the foundset does not clear after the update.

I meant this

databaseManager.refreshRecordFromDatabase(Object foundset, number recordIndex)

Adding a refresh records doesn’t change anything. Nothing I do seems to shed any more light on why this is happening. This is the method that causes the problem. It is a global method attached to the onDataChange of a checkbox. I have tried it on the onAction and it does the same thing.

var formName	= application.getMethodTriggerFormName();
var elementName	= application.getMethodTriggerElementName();
var columnName	= forms[ formName ].elements[ elementName ].getDataProviderID();

var theFoundset	= forms[ formName ].foundset;
var theIndex	= theFoundset.getSelectedIndex();

application.output( "Before Update: " + formName + " | " + elementName + " | " + columnName + " | " + theFoundset.getSize() );

var fsUpdater = databaseManager.getFoundSetUpdater( theFoundset );

fsUpdater.setColumn( columnName, 0 );
fsUpdater.performUpdate();

application.output( "After Update: " + forms[ formName ].foundset.getSize() );

databaseManager.refreshRecordFromDatabase(theFoundset, theIndex );

forms[ formName ].controller.setDataProviderValue( columnName, 1);

The idea is that while viewing a contact’s details, the user can select that this contact should be the default contact of this contact’s client’s jobs. Setting the value of the ‘use_contact_as_defalut’ column on the selected record to 1 needs to set the value in all the other contacts for this client to 0. The form that show in the Form In Dialog has no controller and no way for the user to change the selected record, but the foundset contains all the contacts for that contact’s clients.

I have identified the culprit and included a sample solution. Here is the scenario:
My main form shows clients in a record view. On the client form is a tabpanel that shows a list of contacts for that client. The tab is relationless and a method attached to the client form’s onRecordSelected calls a method in the contact list view form that loads the current client’s contacts into the foundset via a dataset derived from a SQL query. Each contact record contains a button that, when clicked, loads a form with the list view’s foundset and displays that form in a form in dialog. On the form in dialog are checkboxes that update the foundset to make sure that, if checked, the current contact is the only contact checked for that client.

With me so far? Here’s the kicker:
The problem occurs when the contact list view form has an initial sort on a related dataprovider. How is that related to anything that the foundset updater is doing?

The sample solution illustrates this problem. Thanks for bearing with me on this.

051025_fsUpdater_in_fid.servoy (58.9 KB)

related sort when you do loadRecords(pkdataset) is not supported.
We will clear the related sort which is there now (we didn’t do that completely so thats why you got the problem)
if you want to sort do this:

controller.loadRecords( dataset );
controller.sort(‘contacts_to_persons.displayname asc’);

Much better is to use a relation for this or use loadRecords(query)

I understand that a relationship would be better, but in some cases, users have fields to enter filter criteria, and a relationship won’t work. I will investigate adding controller.sort() to my method, but I am concerned as I seem to recall that certain events caused the sort in the tabpanels to be lost.

still don’t get it right why you can’t use relations.
Where do they enter filter criterea?
You can use global variables for those filter criteria and use those in a relation.

Relations are just searches but handled by servoy itself. So they will be cached must better.

what should be avoided is loadRecords(pkdataset) this is just for very very specific circumstances.
Try to use these (in that order)

1> use relations if possible
2> do a find in a form (controller.find() controller.sort() controller.search())
3> loadRecords(query)