Problem adding related record via portal

The problem I’m having seems to come down to the fact that .newRecord() doesn’t initially add a new record to the database, but rather just adds a line to my portal, and so subsequent script operations fail.

I’m creating a form that displays a record from the table ‘joborder’. The form contains a portal that displays all of the records in the table ‘scanset’ that relate to the current job order. Basically, your garden variety one-to-many relationship.

I want to put a button on the main form that creates a new related record (adds a row to the portal) and then brings up a form to edit that new record. Here’s the script attached to that button:

// Create a new scan set
joborder_to_scanset.newRecord();
joborder_to_scanset.date_created = application.getTimeStamp();

// Edit the new scanset
var dataset = databaseManager.convertToDataSet(joborder_to_scanset.scansetid.toString());
forms.ScanSet.controller.loadRecords( dataset );
application.showFormInDialog( forms.ScanSet );

Problem is, this script doesn’t work right. When the ScanSet form comes up, it is editing the “null record”. When you attempt to edit any fields, you get the “No record, create one first” error.

I believe I have discovered what is going on. If I run the script, and while the ScanSet form is displayed, look at the ‘scanset’ table using an alternate tool, I see that the new record doesn’t yet exist in the table. This is why the attempt to edit the new record fails…it doesn’t really exist yet.

I’ve noticed that it goes further than this. When I exit out of the ScanSet form, I notice that the new record HAS been added to the portal view and is the selected item. But now if I hit my “Edit” button to edit the current portal row, I still have the same problem. And if I again look at the table with an external tool, the record STILL has not been added to the database. The “Edit” button works fine for other rows in the portal.

If I click in one of the fields of the new row of the portal and THEN press the Edit button, now I get the correct behavior and I can edit that record. Clicking in and then exiting a field in the row seems to finally cause the record to actually be saved.

Is this a bug? What can I do to get around this problem? I’ve looked, and there doesn’t seem to be any sort of “Save” method to force the new portal contents to be written to the database. Should I be doing this differently?

:P TIA for any help.

Steve

Oops. I forgot to mention the specifics of my system…

I’m running the latest Servoy beta release, 2.0 rc3. I’m on Windows XP, and am running JDK version 1.4.2_03. My backend db is postgresql.

Steve

did you add a saveData() line?
It doesnt save to the database until you do that or exit executing a method. That’s on purpose so that Servoy doesn’t have to perform 99 database updates if you are filling a 99 column table.

Doh! I had looked for some sort of “save” on the relation or portal itself, but didn’t think to try saveData() on the outer record. Thanks much!

Sorry to be such a newbie.

Steve

Blatwurst:
Sorry to be such a newbie.

Steve

No problem. It’s only thanks to all the great questions on this forum that we are able to improve our documentation and product continuosly.