# autoincrement fields

**URL:** <https://forum.servoy.com/t/autoincrement-fields/1619>\
**Category:** Classic Servoy\
**Created:** [April 1, 2004, 8:23pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619 "2004-04-01T20:23:40Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![gul\_irfan](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@gul\_irfan](https://forum.servoy.com/u/gul_irfan)\
**Post date:** [April 1, 2004, 8:23pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/1 "2004-04-01T20:23:40Z")

</div>

I made a forma nd placed a field there. Then I made a method that creates new record and placed a button that calls that method.  
The problem is that when a record is created the field that should autoincrement gets set to 0, and only if I go to designer mode and then back I get field to autoincrement.

I used controller.newRecord() in a method.  
What may I be 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:** [April 1, 2004, 9:01pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/2 "2004-04-01T21:01:45Z")

</div>

Can you show what your method looks like and which version you use?

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [April 1, 2004, 9:23pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/3 "2004-04-01T21:23:06Z")

</div>

database auto increment?

then you first have to do a save…

What happens for example if you create 2 newRecords after each other.. What id does the first one have?

---

<div class="post-metadata">

**Author:** ![gul\_irfan](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@gul\_irfan](https://forum.servoy.com/u/gul_irfan)\
**Post date:** [April 2, 2004, 6:20pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/4 "2004-04-02T18:20:33Z")

</div>

here is the method:  
controller.newRecord();  
that’s all I did.  
If I create two after each other, they both get set to 0 until I go to designer mode and back, then they are set to right values.  
I use latest evaluation version on Windows XP  
Thank you

---

<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:** [April 2, 2004, 6:22pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/5 "2004-04-02T18:22:58Z")

</div>

Is the increment set by Servoy or by the database itself?

---

<div class="post-metadata">

**Author:** ![gul\_irfan](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@gul\_irfan](https://forum.servoy.com/u/gul_irfan)\
**Post date:** [April 2, 2004, 8:17pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/6 "2004-04-02T20:17:49Z")

</div>

by the database, but I need to keep it by database , because I want to build web site for that database

---

<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:** [April 2, 2004, 8:20pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/7 "2004-04-02T20:20:14Z")

</div>

In that case did you pay attention to the remark of Johan about performing a save (controller.saveData()) after performing the controller.newRecord();

---

<div class="post-metadata">

**Author:** ![gul\_irfan](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@gul\_irfan](https://forum.servoy.com/u/gul_irfan)\
**Post date:** [April 2, 2004, 8:29pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/8 "2004-04-02T20:29:06Z")

</div>

this is how my method looks like now:

controller.newRecord();  
controller.saveData();

still same problem, I even restarted servoy to make sure the method is saved.

Who is Johan and where did he say that?

---

<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:** [April 2, 2004, 8:32pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/9 "2004-04-02T20:32:35Z")

</div>

Johan = Johan Compagner from Servoy also replying to your post earlier.

But anyway, I am out of options maybe the guys from Servoy can help you further. Sorry…

---

<div class="post-metadata">

**Author:** ![gul\_irfan](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@gul\_irfan](https://forum.servoy.com/u/gul_irfan)\
**Post date:** [April 2, 2004, 8:34pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/10 "2004-04-02T20:34:23Z")

</div>

this is funny  
I changed my method like this:

controller.newRecord();  
controller.sort(String);

and it worked.  
Note I didn’t even replace the ‘String’

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [April 2, 2004, 8:39pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/11 "2004-04-02T20:39:59Z")

</div>

are you sure that it really didn’t get saved or is the pk just not updated quite right after the save?

when you start servoy with java.exe -DSTACKTRACE=TRUE -jar servoy\_developer.jar

you will see something like this when you call controller.saveData()

sql insert into test(TESTID,INTEGER1,DATE1,TEKST) values (?,?,?,?,?,?)  
questiondata[2] 1  
questiondata[3] -10  
questiondata[4] 1970-01-01 00:00:00.0  
questiondata[5]

do you see that?  
And what output around that do you also see?

Can you send me a reproducable example solution where i can see that youre pk is never updated?

What database do you use?

---

<div class="post-metadata">

**Author:** ![gul\_irfan](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@gul\_irfan](https://forum.servoy.com/u/gul_irfan)\
**Post date:** [April 2, 2004, 8:58pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/12 "2004-04-02T20:58:28Z")

</div>

Johan, (I understand you are Johan)

I’m attaching the picture of what I get… hope I did what you told me to.

I’m using MySQL which is on other machine(OSX) I tie in to it using Windows

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [April 2, 2004, 9:03pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/13 "2004-04-02T21:03:24Z")

</div>

what is youre pk column for that table?  
do you configured it as a database sequence in the dataprovider dialog?

---

<div class="post-metadata">

**Author:** ![gul\_irfan](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@gul\_irfan](https://forum.servoy.com/u/gul_irfan)\
**Post date:** [April 2, 2004, 9:11pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/14 "2004-04-02T21:11:31Z")

</div>

Johan, you are dealing with recent graduate girl, and I still don’t understand many things…  
I assume you mean Primary Key by ‘pk’ and I don’t understand what you mean by database sequence.  
I’m attaching a picture of how the data provider is set, hope it will help.

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [April 2, 2004, 9:23pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/15 "2004-04-02T21:23:44Z")

</div>

ok i see youre problem..

JobNumer is youre primary key.. But youre sequence type of that row (last column) is none. You have to set that to the sequence type you want and that is database sequence…

or else servoy doesn’t know that you are using a database sequence.

---

<div class="post-metadata">

**Author:** ![gul\_irfan](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@gul\_irfan](https://forum.servoy.com/u/gul_irfan)\
**Post date:** [April 2, 2004, 9:28pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/16 "2004-04-02T21:28:16Z")

</div>

OK, then I have another question.  
When I just create a new field I can set the database sequence, but if the field is already created I am not able to change it.  
Can you tell me how to change it?

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [April 2, 2004, 9:29pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/17 "2004-04-02T21:29:17Z")

</div>

what version of servoy do you use?  
because that is fixed some builds ago!

---

<div class="post-metadata">

**Author:** ![gul\_irfan](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@gul\_irfan](https://forum.servoy.com/u/gul_irfan)\
**Post date:** [April 2, 2004, 9:30pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/18 "2004-04-02T21:30:40Z")

</div>

this is what it says in about section

Servoy Developer  
Version R2 2.0 beta6-build 260

Copyright M-) 1997-2003  
Servoy BV  
[www.servoy.com](http://www.servoy.com)

I’m using evaluation version that I downloaded about a week ago

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [April 2, 2004, 9:32pm UTC](https://forum.servoy.com/t/autoincrement-fields/1619/19 "2004-04-02T21:32:34Z")

</div>

thats an old version yes

see

[http://forum.servoy.com/viewtopic.php?t … eta+update](http://forum.servoy.com/viewtopic.php?t=1181&highlight=beta+update)

or you can wait for RC11 which should be around the corner pretty soon as a complete download.
