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?
TIA for any help.
Steve