# Force an in-mem record save

**URL:** <https://forum.servoy.com/t/force-an-in-mem-record-save/13207>\
**Category:** Classic Servoy\
**Created:** [November 19, 2010, 12:31pm UTC](https://forum.servoy.com/t/force-an-in-mem-record-save/13207 "2010-11-19T12:31:35Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![victor.rojo](https://avatars.discourse-cdn.com/v4/letter/v/57b2e6/32.png) [@victor.rojo](https://forum.servoy.com/u/victor.rojo)\
**Post date:** [November 19, 2010, 12:31pm UTC](https://forum.servoy.com/t/force-an-in-mem-record-save/13207/1 "2010-11-19T12:31:35Z")

</div>

Hi,  
I create a datasource from a dataset. Then I create a relation with solution model from a table to this datasource. In a modal dialog I create records through the relation. Here is my problem.  
If the program isn’t in a transaction (autosave=true) when the dialog is closed I have all the created records in the dataset, that’s ok. But when the program is in a transaction (autosave = false) I haven´t the records in the dataset until the transaction ends (and autosave = true).  
Is there any function to force the save to the dataset?  
I tried to use databaseManager.saveData([record]) but it returns false.

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [November 19, 2010, 12:40pm UTC](https://forum.servoy.com/t/force-an-in-mem-record-save/13207/2 "2010-11-19T12:40:43Z")

</div>

Hi Victor,

saveDate() should work. Perhaps something obvious but are you using this exact syntax databaseManager.saveData([record]) ?  
If so then that is wrong. The [record] is an optional parameter. Just use databaseManager.saveData() to save any unsaved data.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![victor.rojo](https://avatars.discourse-cdn.com/v4/letter/v/57b2e6/32.png) [@victor.rojo](https://forum.servoy.com/u/victor.rojo)\
**Post date:** [November 19, 2010, 12:59pm UTC](https://forum.servoy.com/t/force-an-in-mem-record-save/13207/3 "2010-11-19T12:59:19Z")

</div>

Hi Robert,

> victor.rojo:  
> databaseManager.saveData([record])

hehe, a quickly copy-paste of the servoy sample.

I tried databaseManager.saveData(foundset[relationName].getRecord(1)) and always return false (before close the modal dialog when there isn´t transaction and after close it in a transaction)

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [November 19, 2010, 1:08pm UTC](https://forum.servoy.com/t/force-an-in-mem-record-save/13207/4 "2010-11-19T13:08:02Z")

</div>

Hi Victor,

Does foundset[relationName].getRecord(1) indeed return a JSRecord object ?

---

<div class="post-metadata">

**Author:** ![victor.rojo](https://avatars.discourse-cdn.com/v4/letter/v/57b2e6/32.png) [@victor.rojo](https://forum.servoy.com/u/victor.rojo)\
**Post date:** [November 19, 2010, 1:31pm UTC](https://forum.servoy.com/t/force-an-in-mem-record-save/13207/5 "2010-11-19T13:31:53Z")

</div>

> ROCLASI:  
> Hi Victor,
> 
> Does foundset[relationName].getRecord(1) indeed return a JSRecord object ?

Yes

```auto
=>foundset[relationName].getRecord(1)
Record {_sv_rowid:DbIdentValue1564054973,pickcolumid:10,selected:1}

```

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [November 19, 2010, 2:48pm UTC](https://forum.servoy.com/t/force-an-in-mem-record-save/13207/6 "2010-11-19T14:48:20Z")

</div>

Have you already checked the reason why the save fails?

databaseManager.getFailedRecords() and then look at the exception property on the record

Paul

---

<div class="post-metadata">

**Author:** ![victor.rojo](https://avatars.discourse-cdn.com/v4/letter/v/57b2e6/32.png) [@victor.rojo](https://forum.servoy.com/u/victor.rojo)\
**Post date:** [November 19, 2010, 4:57pm UTC](https://forum.servoy.com/t/force-an-in-mem-record-save/13207/7 "2010-11-19T16:57:43Z")

</div>

> pbakker:  
> Have you already checked the reason why the save fails?
> 
> databaseManager.getFailedRecords() and then look at the exception property on the record
> 
> Paul

Yes… and doesn´t return anything

---

<div class="post-metadata">

**Author:** ![rgansevles](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rgansevles](https://forum.servoy.com/u/rgansevles)\
**Post date:** [November 24, 2010, 11:33am UTC](https://forum.servoy.com/t/force-an-in-mem-record-save/13207/8 "2010-11-24T11:33:25Z")

</div>

Victor,

When you want to save the related records in the dataset, is the main (regular db record) already saved?  
From what you showed it seems that this is a dbident table and if the record has not been saved yet you cannot save related records with that fk.  
A dbident value only gets known when the record is saved, until then in memory there is a placeholder (DbIdentValue1564054973).

Rob

---

<div class="post-metadata">

**Author:** ![victor.rojo](https://avatars.discourse-cdn.com/v4/letter/v/57b2e6/32.png) [@victor.rojo](https://forum.servoy.com/u/victor.rojo)\
**Post date:** [November 25, 2010, 7:46am UTC](https://forum.servoy.com/t/force-an-in-mem-record-save/13207/9 "2010-11-25T07:46:38Z")

</div>

> rgansevles:  
> When you want to save the related records in the dataset, is the main (regular db record) already saved?

Yes.

> rgansevles:  
> From what you showed it seems that this is a dbident table and if the record has not been saved yet you cannot save related records with that fk.  
> A dbident value only gets known when the record is saved, until then in memory there is a placeholder (DbIdentValue1564054973).

The \_sv\_rowid field of the record is only in the foundset not in the dataset. Its created by Servoy when a foundset is created from a dataset.

But I find the problem… I was testing it from the Interactive Console where the saveData() returns false… (also with records from a table)  
If I try it running the solution the record is saved to the dataset.  
Another question, databaseManager.convertFoundSet(foundset,relation) should work?

---

<div class="post-metadata">

**Author:** ![rgansevles](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rgansevles](https://forum.servoy.com/u/rgansevles)\
**Post date:** [November 26, 2010, 5:17pm UTC](https://forum.servoy.com/t/force-an-in-mem-record-save/13207/10 "2010-11-26T17:17:18Z")

</div>

> victor.rojo:  
> I was testing it from the Interactive Console where the saveData() returns false… (also with records from a table)  
> If I try it running the solution the record is saved to the dataset.

There is a problem with saving data from the debugger, something with saving from another thread than from the app.  
This is fixed in Servoy 6.

> victor.rojo:  
> Another question, databaseManager.convertFoundSet(foundset,relation) should work?

This function only works with relations within 1 server (because the 2 tables in the relation are joined in sql).  
A relation from a real table to an in-memory table is across 2 ‘servers’ and therefore this is not possible.  
It is possible with a relation between 2 in-memory tables, they are on the same ‘server’.

Rob

---

<div class="post-metadata">

**Author:** ![victor.rojo](https://avatars.discourse-cdn.com/v4/letter/v/57b2e6/32.png) [@victor.rojo](https://forum.servoy.com/u/victor.rojo)\
**Post date:** [November 29, 2010, 7:32am UTC](https://forum.servoy.com/t/force-an-in-mem-record-save/13207/11 "2010-11-29T07:32:16Z")

</div>

Ok,  
Thanks Rob.
