I upgraded a solution from Servoy 3 to Servoy 5.2.7 build 1013, and I’m experiencing a problem with a method creating and editing a record. The record gets created, but fields are not properly being set. For example a simple number field could get set to the value 5, if I evaluate the field in the Interactive console it shows a value of 5, but if I look at the back end data with a query browser the value of the field is 0. When the method completes, the servoy client then reverts to having a value of 0 for that field. It only holds it’s value while I’m debugging, and the backend never gets it.
I am using databaseManager.saveData() but it’s not saving. This wasn’t a problem in servoy 3. Does anyone know a trick to ensure that the data gets stored correctly in the backend?
Does databaseManager.saveData() return true or false ?
If false then Servoy can’t save the data. You can get the failed records and the error using the databaseManager.getFailedRecords() like so:
if (!databaseManager.saveData()) {
var _aFailed = databaseManager.getFailedRecords();
for (var i=0; i < _aFailed.length; i++) {
Application.output('Error in save : ' + _aFailed[i].exception, LOGGINGLEVEL.ERROR);
}
}
I just said committed because I wasn’t sure how else to describe the situation where the column shows one value in the debugger and another in MySQL. And the value MySQL shows is the default value of the column, so it’s not like sometimes I am able to change the value of these columns. This is occurring for both number and text columns.
This is still a big problem for me. I have some more info from more tests:
Right after creating the record I run databaseManager.saveData() and that returns true.
Then I store the primary key in a variable. The value of the variable is the correct primary key for the newest record that appears through a query browser.
controller.loadRecords("SELECT pk_id FROM tableWHERE pk_id = " + pk_variable);
which also returns no records. So the record is created in the back end, but it cannot be modified by servoy, and it cannot be found by servoy. What’s going on here?
Here is the complete code I’m using. Something else to note, this method is being called by another method that is initiated from a form in a dialog. Could that have anything to do with it?
controller.newRecord(true);
var check = databaseManager.saveData();
var pk_var = pk_id;
//databaseManager.refreshRecordFromDatabase(-1);
//controller.find();
//pk_id = pk_var;
//controller.search();
controller.loadRecords("SELECT pk_id FROM table WHERE pk_id = " + pk_var);
return pk_var;
None of the commented out steps work. I am left with no records found after executing the controller.loadRecords step. Doing a find in the calling method doesn’t work either.
Did you accidentally make a new variable in your function, or a form variable, with the same name as a column in your table? If so, you would be confusing Servoy. like do you have a form variable called “pk_id”?
Also, what are you using for your table PK sequences? MySQL auto_increment, or Servoy Sequences?
I’m seeing something similar, also in 5.2.7
Invoices form has a related field from the patients table as a combobox. OnDataChange triggers a saveData() and then calls a headless client to do some stuff. However the HC does not always see the changes to the field.
No, there are no variables named the same as a column.
I had this method that worked fine in 3, and now I’m doing everything I can to troubleshoot it in 5.2.7. I tried to find the record after it was saved and it is not found. If I clear the found set and then create the record, the interactive console shows the record, and its modified data but MySQL does not, and after the method completes servoy does not see it anymore.
This method is being called from a form in dialog, so I tried closing the dialog before creating the record, still no luck, however the method runs, other steps execute correctly, just not editing this one record. If I go to the form itself and manually create and edit the record, that works, it’s just this method that cannot edit the record.
I tired an SQL statement to find a record that was created in a previous attempt through it’s known pk_id, and servoy does not find the record although it does show up in a query browser, but with only default values entered not the values entered by this method.
I have a similar, but probably unrelated problem. In 5.2.7 in creating a child file in ‘assigned’ table from the parent ‘contacts’ table the child is created and populated with various fields including the assignee’s name. The assignee’s name is displayed in a contacts line item.
The name will appear after creation as several new assignments are being made. Then the name may not appear on the next assignment. The assignment after that it may appear correctly. Seems to be totally random whether or not the name will be rendered. However in the assigned table, in every case the child records are totally correct. When I log out of the solution and log back in, the assignee’s name appears every time on all records.
If I do a search on the assigned name when several assigned names are showing blank, the search result includes the records showing blank names.
I’ve tried DatabaseManager refreshRecordFromDatabase. No luck.
This problem did not appear in earlier versions of Servoy.
Even though I am editing this record through a form with a foundset and not through a relationship, there is a foreign key that needs to be populated before edits can stick. The method is not using any relationships based on this key and the column is allowed to be null, but for some reason it needs to be populated first before any other edits can stick. Again, this was not the case in Servoy 3. Pretty weird, but thanks for all the ideas everyone.