# OmitRecord problem

**URL:** <https://forum.servoy.com/t/omitrecord-problem/2642>\
**Category:** Classic Servoy\
**Created:** [September 5, 2004, 4:44am UTC](https://forum.servoy.com/t/omitrecord-problem/2642 "2004-09-05T04:44:46Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![gstein](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@gstein](https://forum.servoy.com/u/gstein)\
**Post date:** [September 5, 2004, 4:44am UTC](https://forum.servoy.com/t/omitrecord-problem/2642/1 "2004-09-05T04:44:46Z")

</div>

I want to remove the first record of a foundset when my people form opens. I’m doing:

forms.people.controller.recordIndex = 1;  
forms.people.controller.omitRecord();

on the OnLoad event, but I still see the record when the form is shown.

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)\
**Post date:** [September 5, 2004, 9:25am UTC](https://forum.servoy.com/t/omitrecord-problem/2642/2 "2004-09-05T09:25:10Z")

</div>

Just a remark and don’t know which version you use but bare in mind that with 2.1 setting the recordindex has changed into: **controller.setSelectedIndex(number index)**.

The omit record function gives you back a boolean. Can you tell if that’s true or false? That should give you some answers…

---

<div class="post-metadata">

**Author:** ![gstein](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@gstein](https://forum.servoy.com/u/gstein)\
**Post date:** [September 5, 2004, 10:03am UTC](https://forum.servoy.com/t/omitrecord-problem/2642/3 "2004-09-05T10:03:31Z")

</div>

I changed my code to:

var myMain = currentcontroller.getName()  
forms.people.controller.setSelectedIndex(1)  
var myVal = forms.people.controller.omitRecord();  
plugins.dialogs.showInfoDialog( “myVal”, myVal)

It didn’t help.

When it runs, the omitRecord returns false – but I’m not sure why or what to do about it…

---

<div class="post-metadata">

**Author:** ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)\
**Post date:** [September 5, 2004, 10:16am UTC](https://forum.servoy.com/t/omitrecord-problem/2642/4 "2004-09-05T10:16:48Z")

</div>

Remark: You can also do application.output(“myVal:”+myVal). I like this better because the output shows in de debugger and doesn’t interfere with the interface of the solution.

As far as I can tell ‘false’ tells you the omit record command failed. We knew that already ![:shock:]( "Shocked") but it is now confirmed…

Are you sure the controller has records. What does getMaxRecordIndex tell you? when you start with that

```auto
var max = forms.people.controller.getMaxRecordIndex();
forms.people.controller.setSelectedIndex(1);
var index = forms.people.controller.getSelectedIndex();
var result = forms.people.controller.omitRecord(); 
application.output( "max:"+max+", index:"+index+", result:"+result);

```

---

<div class="post-metadata">

**Author:** ![gstein](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@gstein](https://forum.servoy.com/u/gstein)\
**Post date:** [September 5, 2004, 10:26am UTC](https://forum.servoy.com/t/omitrecord-problem/2642/5 "2004-09-05T10:26:06Z")

</div>

Nice trouble-shooting code.

That helped identify the problem.

When I ran it, MaxRecords, SelectedIndex, and OmitRecords were 0, 0, false.

I moved the method to the OnShow event rather than the OnLoad event and it worked fine. I guess the OnLoad event fires before the foundset is loaded.

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)\
**Post date:** [September 5, 2004, 10:40am UTC](https://forum.servoy.com/t/omitrecord-problem/2642/6 "2004-09-05T10:40:36Z")

</div>

aha… That’s it.

Your first post stated ‘when my people form opens’. That’s not true if you do this onLoad! With an onLoad you only ‘load’ the form. This event can be used to set element visibility etc. or whatever things you want to be done BEFORE you show the form for the first time.

What you could do however, if you ONLY want/need to omit on the first show of the form, is put the following code into your method attached to the onShow event:

```auto
var firstShow = arguments[0];
if (firstShow)
{
	//your code;
}

```

This way you check if the form is shown for the first time and it is only then that you method gets executed.

---

<div class="post-metadata">

**Author:** ![maria](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@maria](https://forum.servoy.com/u/maria)\
**Post date:** [June 11, 2010, 12:51am UTC](https://forum.servoy.com/t/omitrecord-problem/2642/7 "2010-06-11T00:51:10Z")

</div>

I think I found a bug.  
At least I wouldn’t expect the following kind of behaviour:  
I was getting false when trying to omit a record.  
Tried everything, checked the number of records, set the index to different record, checked the relations between the forms, etc.  
The record just wouldn’t omit.  
I have just thought there’s something special about this particular record (others were omitting successfully), and this something was that it has a value in one of its fields that is used in a rowBGCalculation global method to color this row in a different color.  
Unassigning the row color method off the form fixed the problem straight away.  
But I would love to be able to use it.  
So, is it a bug or was I doing anything wrong?

Cheers,  
Maria

---

<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:** [June 11, 2010, 7:43am UTC](https://forum.servoy.com/t/omitrecord-problem/2642/8 "2010-06-11T07:43:01Z")

</div>

Maria,

You cannot access any data (like omitting records) in the form onLoad event, the foundset is not initialized yet at that point.  
Instead you can use the form onsHow event, the boolean arg firstShow can be used to make sure you onit only once.

Rob

---

<div class="post-metadata">

**Author:** ![maria](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@maria](https://forum.servoy.com/u/maria)\
**Post date:** [June 15, 2010, 10:55pm UTC](https://forum.servoy.com/t/omitrecord-problem/2642/9 "2010-06-15T22:55:59Z")

</div>

> rgansevles:  
> Maria,
> 
> You cannot access any data (like omitting records) in the form onLoad event, the foundset is not initialized yet at that point.  
> Instead you can use the form onsHow event, the boolean arg firstShow can be used to make sure you onit only once.
> 
> Rob

Rob, I’m not omitting records in the form onLoad event or onShow.  
It happens when the user performs certain actions while viewing the form.

---

<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:** [June 16, 2010, 7:08am UTC](https://forum.servoy.com/t/omitrecord-problem/2642/10 "2010-06-16T07:08:03Z")

</div>

Maria,

I got confused with the start of this thread.

omitRecord will try to save the record when it is edited, when this is blocked somehow the omit fails.  
The rowbgcolorcalc seems to block this (does the calc change data?)

Can you show this in a small sample?

Rob
