# Records not saving

**URL:** <https://forum.servoy.com/t/records-not-saving/18478>\
**Category:** Classic Servoy\
**Created:** [June 2, 2015, 12:05pm UTC](https://forum.servoy.com/t/records-not-saving/18478 "2015-06-02T12:05:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve1376656734](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/steve1376656734/32/4613_2.png) [@steve1376656734](https://forum.servoy.com/u/steve1376656734)\
**Post date:** [June 2, 2015, 12:05pm UTC](https://forum.servoy.com/t/records-not-saving/18478/1 "2015-06-02T12:05:25Z")

</div>

Hi,

I am struggling to get my head around a problem I am getting with records being saved. I am finding that my record with a calculation is not being saved to the database and when I run a debug session I can see that there is an unsaved record (using databaseManager.getEditedRecords()) but nothing I do seems to be able to get this record saved to the database. Below is a transcript from the Interactive console which shows there is 1 edited record which is for the table case\_stage. If I then issues a databaseManager.saveData() the return value is false which indicates an error has occurred and running databaseManager.getEditedRecords().length shows there is still 1 edited record. A further attempt to save the record is also false but if I run databaseManager.getFailedRecords() it returns nothing!!!

```auto
=>databaseManager.getEditedRecords().length
1.0
=>databaseManager.getEditedRecords()[0].getDataSource()
"db:/mydb/case_stage"
=>databaseManager.saveData()
false
=>databaseManager.getEditedRecords().length
1.0
=>databaseManager.saveData()
false
=>databaseManager.getEditedRecords().length
1.0
=>databaseManager.saveData()
false
=>databaseManager.getFailedRecords()

=>databaseManager.getEditedRecords().length
1.0
=>databaseManager.getEditedRecords()[0].getChangedData()
{rowColumns:["col_name","old_value","new_value"],rowIndex:-1,row_1:[(1) col_name:"completed_on",(2) old_value:2015-03-02 14:22:06.78,(3) new_value:null]}
=>

```

Can anyone give me a clue as to what is happening please?

Thanks  
Steve

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [June 2, 2015, 2:16pm UTC](https://forum.servoy.com/t/records-not-saving/18478/2 "2015-06-02T14:16:14Z")

</div>

Any database events that might contain errors?  
My experience is that these fail quite silently…

---

<div class="post-metadata">

**Author:** ![steve1376656734](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/steve1376656734/32/4613_2.png) [@steve1376656734](https://forum.servoy.com/u/steve1376656734)\
**Post date:** [June 2, 2015, 2:40pm UTC](https://forum.servoy.com/t/records-not-saving/18478/3 "2015-06-02T14:40:42Z")

</div>

Nothing out of the ordinary showing in the PostgreSQL log at all. I am running PostgreSQL 9.4 and Servoy 7.4.4 on OS X Yosemite and it is driving me nuts. I’m also having a related issue with calculations on these same records which may or may not be causing the problem. I have three tables related as follows:

case\_stage ← one to many → case\_report ← one to many → case\_report\_expert

case\_report\_expert has cancelled\_on and completed\_on fields.  
case\_report has stored calculations cancelled\_on and completed\_on that are based on the related case\_report\_expert records  
case\_stage has stored calculations cancelled\_on and completed\_on that are based on the related case\_report records

If I make a change to a case\_report\_expert record the calculations are correctly updated for the case\_report record but not for the case\_stage and I can’t figure out why and this appears to be related to the error I’m getting above.

Any suggestions would be welcome.

Thanks  
Steve

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [June 3, 2015, 8:31am UTC](https://forum.servoy.com/t/records-not-saving/18478/4 "2015-06-03T08:31:12Z")

</div>

With DB Events I was more pointing towards Servoy’s DB Event handlers.

It’s kind of hard to say what goes wrong.  
Nothing in application server log as well?

---

<div class="post-metadata">

**Author:** ![steve1376656734](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/steve1376656734/32/4613_2.png) [@steve1376656734](https://forum.servoy.com/u/steve1376656734)\
**Post date:** [June 3, 2015, 8:41am UTC](https://forum.servoy.com/t/records-not-saving/18478/5 "2015-06-03T08:41:52Z")

</div>

After a lot of debugging work I can see the following happening and am wondering if this is normal:

1. Start a transaction
2. Update the child record (this will affect the calculations in both the parent and grandparent record)
3. Save the child record (databaseManager.saveData(childRecord)
4. Save the parent record (databaseManager.saveData(parentRecord)
5. Save the grandparent record (databaseManager.saveData(grandparentRecord)
6. Commit the transaction

At the end of this I would expect everything to be saved and up to date but if I set a breakpoint immediately after the transaction has been committed and issue a databaseManager.getEditedRecords() I can see the the parent record is showing as having changes and getRecordChanges() shows it is the calculation that has been changed.

For now the only solution I have been able to find is to manually do a databaseManager.recalculate() on the parent and grandparent records immediately before the databaseManager.saveData() and this then leaves all the records clean when the transaction completes.

I’d love to know why the calculation is triggered only AFTER the transaction has been committed.

Thanks  
Steve

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [June 3, 2015, 1:49pm UTC](https://forum.servoy.com/t/records-not-saving/18478/6 "2015-06-03T13:49:25Z")

</div>

Hi Steve,

I have had endless fun with calculations on older versions of Servoy. In the end I solved the problems by removing the troublesome calculations and updating the fields manually during table events.

One thing to watch out for is running manual SQL queries during updates of data structures – the data may not be saved yet so the database does not see it.

PostgreSQL 9.4 and Servoy 7.4.4 on OS X Yosemite is not causing me any particular problems. The stack seems pretty stable at the moment.

Christian

---

<div class="post-metadata">

**Author:** ![steve1376656734](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/steve1376656734/32/4613_2.png) [@steve1376656734](https://forum.servoy.com/u/steve1376656734)\
**Post date:** [June 3, 2015, 4:40pm UTC](https://forum.servoy.com/t/records-not-saving/18478/7 "2015-06-03T16:40:51Z")

</div>

Hi Christian,

I wouldn’t exactly call it fun but it is certainly endless!! The one I have totally given up on is aggregations - I cannot get these to work at all. I have a foundset with a single record and a MAX() aggregation on a date field which has a valid date and the aggregation value is null!

I’ll stick with the explicit recalculate call for now and see what happens ![:(]( "Sad")

Thanks  
Steve

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [June 3, 2015, 7:53pm UTC](https://forum.servoy.com/t/records-not-saving/18478/8 "2015-06-03T19:53:37Z")

</div>

Hi Steve,

I don’t know the code of your calculation, but from what you’re writing I get the understanding that you use relations within the calculation.  
As Christian already mentioned: endless fun.  
The best advise is: stop using them.  
Calculations are only useful when you calculate within a table (ie. concatenating text fields, create subtotals, etc.)  
Otherwise it will dramatically slow down your solution in the end.

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [June 3, 2015, 10:06pm UTC](https://forum.servoy.com/t/records-not-saving/18478/9 "2015-06-03T22:06:50Z")

</div>

Using relations in calculations to aggregate is just fine. I have hundreds of them in tables with 500k records. No issue at all. But yes, using relations in a calculation and looping over the relation is very bad…
