how to set the entity id starting  with 10000 in outsystems studio

how to set the entity id starting  with 10000 in outsystems studio

  

Hello, can you tell me  how to set the entity id starting value, for example, I create a new entity, and I want  the id start with 10000, how to set up in outsystems service studio? Thank you very much!

If you are using an standard "Id", you can't, as it is autonumber and so, it will be the database to define the number for each new record.

You can make your id NOT autonumber, but then you will have to provide every I'd for a new record yourself and guarantee that each one will receive a unique number/text (depending on type).

You can also keep the standard id and create a new field that will store the values you want to put there.

By the way, why do you need to define the start point of the id? 

Cheers,

Eduardo Jauch

Hey Guys

Im new to the Outsystems platform but I know you can set the Identity seed to that value.

For example when you create your table you can do something like this:

"id int IDENTITY(10000,1)"

Or alter your table??


Like I said I'm new to the Outsystems world not sure if one can do this?


Kind regards 

Benji

I found this on Stack Overflow

Hope this will help https://stackoverflow.com/questions/2130635/how-to-make-a-primary-key-start-from-1000

Hello Benji,

When you create an Entity, the table is created by the platform for you and that is not an option. 

So, unless you create the tables yourself and late import them with the integration studio, I don't think this is possible.

But I also fail to see why one would want to do this in the first place.

It is a question of concept. The idea of the identifier is to uniquely identify a record, not to provide information through the identifier itself.

But as I said, it is possible if you are willing to take care of the enumeration yourself.

Another possibility would be, in the first publishing of the entity, create a bootstrap that would create and erase records until the desired id number is reached, but this is really a nonsense to me.

If the reason to have a starting number is to provide some compatibility with a different system, I would use another field to do that. Not through the identifier.

Hey Eduardo

I agree with you 100%. I also fail to see why one would want to do that.

Thinking about it, it make sense to create an extra field to do that. Otherwise it can become really "hacky".


Thank you,I would like to use id as a product code to the unique encoding, coding needs to start from 5 digits. I do not want to set by manual , hoping to automatically start from the 5-digit number, but do not know how to set

Hi Thomas, 

You can create a new field ProductCode, that is integer/long integer (NOT autonumber)

Every time you create a NEW product, you query the product entity to return the record with the biggest "ProductCode" and insert the new one with "ProductCode + 1".

If it is zero (is the first), you just give the value you want (1000).

This way the value is given automatically and you don't have to use the ID to do that.
Sure you can use the ID as NOT autonumber and do the same thing, but I advise against it.

Cheers,
Eduardo Jauch

Eduardo Jauch wrote:

Hi,Eduardo Jauch,If I do not use the automatic, how to assign id, and id can automatically grow in each assignment. Thank you!



Eduardo Jauch wrote:

Thank you for your advise .If more than one person at the same time to add products, will there be mistakes?



Hello Thomas. 

The last test I did worked as a charm, but I can't say that it is a bullet proof method. Probably an advanced query that insert data and use a subquery to provide the code would be less likely to give problems.

But even than duplicates or error in case duplicates are not permitted would happen. Or could.

You could also have a "pool" of available codes and store the next available code in database. Every time one asks for a code, the value is updated (use a GetForUpdate action), and this way probably the conflicts would not happen even in a heavy user scenario.