# Table Events: Limitations

**URL:** <https://forum.servoy.com/t/table-events-limitations/8003>\
**Category:** Classic Servoy\
**Created:** [August 10, 2007, 8:23pm UTC](https://forum.servoy.com/t/table-events-limitations/8003 "2007-08-10T20:23:09Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![sdevlin](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/sdevlin/32/4488_2.png) [@sdevlin](https://forum.servoy.com/u/sdevlin)\
**Post date:** [August 10, 2007, 8:23pm UTC](https://forum.servoy.com/t/table-events-limitations/8003/1 "2007-08-10T20:23:09Z")

</div>

Is it OK to create related records in a table event?

Because I’ve tried it and I get strange behavior.  
Essentially, the child record is created, but the save never happens.  
So with auto save, every time i “click out”, the table event is run again, but the changes are never comitted. (The little ‘e’ in the status bar never goes away)

If I programmatically add controller.saveData() to my new record method, i get a concurrent modification exception.

What am i doing wrong, or is it just not going to work to have related records created in the table event? Here’s some example code.

Table Event Example Code:

```auto
//	The record argument 
var record = arguments[0];

// Rule: All parent records MUST have one CHILD record to start with
//	--------------------------------------------------
	
	
	//	create child record
	record.parents_to_children.newRecord();

//	--------------------------------------------------

// passed all rules
return true;

```

Servoy Developer  
Version 3.5-build 513  
Java version 1.5.0\_10-b03 (Windows XP)

---

<div class="post-metadata">

**Author:** ![Andrei\_Costescu](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@Andrei\_Costescu](https://forum.servoy.com/u/Andrei_Costescu)\
**Post date:** [August 16, 2007, 2:51pm UTC](https://forum.servoy.com/t/table-events-limitations/8003/2 "2007-08-16T14:51:01Z")

</div>

What event exactly are you using?  
I want to reproduce the behavior.

---

<div class="post-metadata">

**Author:** ![sdevlin](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/sdevlin/32/4488_2.png) [@sdevlin](https://forum.servoy.com/u/sdevlin)\
**Post date:** [August 16, 2007, 4:19pm UTC](https://forum.servoy.com/t/table-events-limitations/8003/3 "2007-08-16T16:19:59Z")

</div>

It is happening on INSERT events

i wanted to add a related record while inserting

i.e. record.relation.newRecord();

---

<div class="post-metadata">

**Author:** ![Robert\_Huber](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Robert\_Huber](https://forum.servoy.com/u/Robert_Huber)\
**Post date:** [August 16, 2007, 4:58pm UTC](https://forum.servoy.com/t/table-events-limitations/8003/4 "2007-08-16T16:58:59Z")

</div>

Hi Sean

I can confirm this, have the same behaviour.

I would like to check for mandatory fields in the table event onInsert, but I am unable to get a sensible result:

This is my code:

> Code:  
> var record = arguments[0];
> 
> if (record.code == null || record.name == null)  
> {  
> plugins.dialogs.showErrorDialog( “Error”, “Code und Fach verlangen eine Eingabe”, ‘OK’);  
> }  
> else  
> {  
> plugins.dialogs.showErrorDialog( “Error”, “Prima”, ‘OK’);  
> forms.ScoSubjectsL.controller.readOnly = true;  
> }

If I enter only a value for code, I get the first time an error when saving (clicking out of the rec, i. e. autosave becomes active).  
Then I click into the record.name field without entering anything and I the record is stored into the db, i. e. no error occurs, which is wrong (as far as I can see).  
So I am able to store invalid records into the db. Can you confirm this as well?

Thanks and best regards, Robert

> sean:  
> It is happening on INSERT events
> 
> i wanted to add a related record while inserting
> 
> i.e. record.relation.newRecord();

---

<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:** [August 16, 2007, 5:23pm UTC](https://forum.servoy.com/t/table-events-limitations/8003/5 "2007-08-16T17:23:39Z")

</div>

Robert, you’re not returning true or false, like in the sample code I provided you with in the other thread. If you do not return false, the insert is not canceled!!!

Paul

---

<div class="post-metadata">

**Author:** ![Andrei\_Costescu](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@Andrei\_Costescu](https://forum.servoy.com/u/Andrei_Costescu)\
**Post date:** [August 17, 2007, 10:23am UTC](https://forum.servoy.com/t/table-events-limitations/8003/6 "2007-08-17T10:23:44Z")

</div>

The data is not saved due to an internal Servoy problem. The behavior is not natural, so we have to treat this scenario properly, either by not supporting such actions inside the table events (and specifying it - treating it nicely) or by making it work.

Please file this issue at [Servoy - Error](http://crm.servoy.com/servoy-webclient/solutions/solution/servoy_support).

Thanks.

---

<div class="post-metadata">

**Author:** ![sdevlin](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/sdevlin/32/4488_2.png) [@sdevlin](https://forum.servoy.com/u/sdevlin)\
**Post date:** [August 17, 2007, 2:39pm UTC](https://forum.servoy.com/t/table-events-limitations/8003/7 "2007-08-17T14:39:06Z")

</div>

Posted to Support System

---

<div class="post-metadata">

**Author:** ![Andrei\_Costescu](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@Andrei\_Costescu](https://forum.servoy.com/u/Andrei_Costescu)\
**Post date:** [August 17, 2007, 2:47pm UTC](https://forum.servoy.com/t/table-events-limitations/8003/8 "2007-08-17T14:47:23Z")

</div>

The issue is corrected in Servoy 3.5.1 and 4.0.  
The data is now saved in both the first table and the related table.

Enjoy ![:)]( "Smile") .

---

<div class="post-metadata">

**Author:** ![Robert\_Huber](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Robert\_Huber](https://forum.servoy.com/u/Robert_Huber)\
**Post date:** [August 17, 2007, 4:13pm UTC](https://forum.servoy.com/t/table-events-limitations/8003/9 "2007-08-17T16:13:40Z")

</div>

Hi Paul, Andrei

Thanks, I added the return values.  
The behaviour of this event is still very strange, we don’t get usable results. The problems so far found (autosave = on):

- The onRecordInsert event is executed 5 times - why??? With this behaviour, it is not possible to put plugins.dialogs.xxx in this event as it is executed 5 times

- If one inserts a record and uses a databaseManager.rollbackEditedRecords(), the selected record is always 1 off, as the onRecordSelection event is executed BEFORE the onRecordInsert event.

- If there is an error and onRecordInsert is fired, the onRecordSelection event is always executed twice and shows once the index of the (newly) added record (which is still not saved as it has an error) and once the index of the clicked record (which triggers the onRecordInsert event, i. e. tries to autosave the record)

- We think the solution could be if the onRecordInsert is fired after the onRecordSelection event, as we then would know the correct record index (we are though not exactly aware of all other possible implications)

- The cmd forms[currentFormName].elements.fldCode.requestFocus() does not work

Conclusion: At the moment we can’t get the onRecordInsert to work as (we think) it is intended (without a lot of workaround programming).  
And as it is called every time 5 times, we can’t put a dialog to inform the user about an error in it as it is executed 5 times anyway.

At the moment, we are stuck and don’t know exactly how to continue, good it’s weekend .-)

Best regards, Robert

> Code of onActionAddRecord, i. e. button add record:  
> /\*  
> Title: Create a new subject
> 
> Author: Robert Huber  
> Created: 16.08.2007  
> Modified: -
> 
> Arguments: -  
> Returns: -  
> Notes: -  
> \*/
> 
> controller.newRecord();  
> setReadOnly(false);

> Code of onRecordInsert:  
> /\*  
> Title: Validate mandatory columns
> 
> Author: Robert Huber, Birgit Rieder  
> Created: 17.08.2007  
> Modified: -
> 
> Arguments: arguments[0] is record being processed  
> Returns: -  
> Notes: -  
> \*/
> 
> var record = arguments[0];  
> var currentFormName = application.getMethodTriggerFormName();
> 
> if (record.code == null || record.code == “” || record.name == null || record.name == “”)  
> {  
> var dialogResult = plugins.dialogs.showErrorDialog( “Error”, “Code und Fach verlangen eine Eingabe”, ‘Abbrechen’, ‘Bearbeiten’);  
> if (dialogResult == “Abbrechen”)  
> {  
> forms[currentFormName].controller.readOnly = true;  
> databaseManager.rollbackEditedRecords();
> 
> // workaround to decrease the record index by one after the onRecordSelection event  
> // add a job that runs at the given date (20 seconds in the future)  
> // and repeats that every 20 seconds for 40 times or the enddate is reached (0 for no repeats = just one call)  
> var startDate = new Date();  
> startDate.setTime(startDate.getTime()+100);  
> var endDate = new Date(startDate.getTime()+100000);  
> plugins.scheduler.addJob(‘in2seconds’,startDate,setIndexMinusOne,20000,0,endDate)
> 
> }
> 
> // needs work (does not yet work):  
> // if (currentFormName != null)  
> // {  
> // forms[currentFormName].elements.fldCode.requestFocus();  
> // }  
> return false;  
> }  
> else  
> {  
> forms[currentFormName].controller.readOnly = true;  
> return true;  
> }

> Code of onRecordSelection:  
> /\*  
> Title: A new record is selected. If the form is in edit mode and the selected  
> record is not the edited record, reselect the edited record and do not  
> allow to select another record.
> 
> Author: Robert Huber, Birgit Rieder  
> Created: 17.08.2007  
> Modified: -
> 
> Arguments: -  
> Returns: -  
> Notes: -  
> \*/
> 
> [//application.output](https://application.output)("selected index: " + forms.ScoSubjectsL.controller.getSelectedIndex());  
> [//application.output](https://application.output)("selected code: " + code);
> 
> if (isReadOnly() == false)  
> {  
> var selectedIndex = controller.getSelectedIndex();  
> if (selectedIndex != editIndex)  
> {  
> controller.setSelectedIndex(editIndex);  
> }  
> }

> pbakker:  
> Robert, you’re not returning true or false, like in the sample code I provided you with in the other thread. If you do not return false, the insert is not canceled!!!
> 
> Paul

---

<div class="post-metadata">

**Author:** ![Andrei\_Costescu](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@Andrei\_Costescu](https://forum.servoy.com/u/Andrei_Costescu)\
**Post date:** [August 20, 2007, 8:08am UTC](https://forum.servoy.com/t/table-events-limitations/8003/10 "2007-08-20T08:08:14Z")

</div>

In the first problem on this thread (the solved one) - the method’s execution was interrupted in the moment a new record was created (and added to the edited record list) because the edited record list changed while Servoy was iterating on it to save records…

I think that in your case the problem might be the same (and thus it might be solved also)… “rollbackEditedRecords” probably changes the edited record list too and thus activates the same bug =\> the rest of the method is not executed any more and no save takes place. So anyway if it is the same problem, strange behavior can happen, as normal execution is interrupted by force…

I am not certain of this, so you can add what you reported in the previous post as another case in the support system + a sample solution to see exactly what is going on.

---

<div class="post-metadata">

**Author:** ![netweaver](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@netweaver](https://forum.servoy.com/u/netweaver)\
**Post date:** [August 22, 2007, 5:45pm UTC](https://forum.servoy.com/t/table-events-limitations/8003/11 "2007-08-22T17:45:54Z")

</div>

Hi  
I have a solution where a dialog saves a new record when running locally in developer, however the same solution does not save a record from the last tabs create dialog.

However i have imported this same solution onto a hosted system running Gentoo linux and have a saving problem with a particaular dialog.

The problem:  
I have modified the sample CRM application, and in this particular problem the last tab, 1 of 2 i added, on the company forms tabs , is not saving the record being created in the dialog.

Any suggestions?  
Thanks  
Marcus

> Andrei Costescu:  
> In the first problem on this thread (the solved one) - the method’s execution was interrupted in the moment a new record was created (and added to the edited record list) because the edited record list changed while Servoy was iterating on it to save records…
> 
> I think that in your case the problem might be the same (and thus it might be solved also)… “rollbackEditedRecords” probably changes the edited record list too and thus activates the same bug =\> the rest of the method is not executed any more and no save takes place. So anyway if it is the same problem, strange behavior can happen, as normal execution is interrupted by force…
> 
> I am not certain of this, so you can add what you reported in the previous post as another case in the support system + a sample solution to see exactly what is going on.

---

<div class="post-metadata">

**Author:** ![Andrei\_Costescu](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@Andrei\_Costescu](https://forum.servoy.com/u/Andrei_Costescu)\
**Post date:** [August 23, 2007, 7:48am UTC](https://forum.servoy.com/t/table-events-limitations/8003/12 "2007-08-23T07:48:10Z")

</div>

Hi,

Your problem apparently has nothing to do with table events.  
Please create another topic for this problem.

Thanks.

---

<div class="post-metadata">

**Author:** ![netweaver](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@netweaver](https://forum.servoy.com/u/netweaver)\
**Post date:** [August 23, 2007, 7:59am UTC](https://forum.servoy.com/t/table-events-limitations/8003/13 "2007-08-23T07:59:48Z")

</div>

The reason i posted it here is that it seems to have a common thread the problem expressed in this thread. The problem being that records are not being save from a dialog, and a message pops up saying the the “data cannot be saved”.  
Thought maybe the context would be considered.  
I will repost to Forms thread.

> Andrei Costescu:  
> Hi,
> 
> Your problem apparently has nothing to do with table events.  
> Please create another topic for this problem.
> 
> Thanks.
