354
Views
7
Comments
Solved
Default value of Entity attribute Id ignores the default value
Question
Platform Version
11.10.0.25600

Hi All,

I am trying to set the default value of the entity attribute to some static value, 1000000, and still keep it AutoNumber. My understanding of this is that the Id will start from 1000000 and since it is set to AutoNumber True it will auto calculate the records ids as 1000001, 1000002, 1000003 etc. If I do not provide the default value in this case then the generated Ids would be 1, 2, 3 etc. However, I am getting the Ids generated as 1, 2, 3 in the first case as well. Here is the snapshot of what I am trying to do:


Platform: OS 11

Application: Reactive Web

Tried on Personal Environment.


Is my understanding incorrect? Can I achieve this without implementing the sequence logic on my own?

Thanks,

Akshay

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

The Default Value for an Attribute is the value that the Attribute has when the Entity Record or Structure is first intialized. So if you, say, create a Local Variable of a certain Structure, then the initial values of the Attributes of that Structure will have the Default Value. You should never set it for an auto-increment Id, because that will have the same effect as assigning that value in the code. Which means it's ignored on a Create, but used for CreateOrUpdate or Update.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Akshay,

Your understanding is unfortunately not correct. You cannot start an auto number from a certain value like that. If you really must, you need access to the database and issue a database-specific command for the physical table (e.g. with DBCC CHECKIDENT on MSSQL).

However, this begs the question: why on earth do you want to control where the auto-number starts? The whole idea of such a number is that you don't care what it is, as long as it's unique.

2023-01-04 05-10-52
Akshay Puri

Thank you Kilian for the response. The need originates from third party I am integrating with requiring values starting from specific point. Although I can create another attribute to store calculated as required, I was curious if the Default Value attribute serves me this readily. With my understanding incorrect, could you please help me understand the purpose of the Default Value attribute? The service studio hint says - "Initial value of this element. If undefined, the default value of the data type is used." 

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

The Default Value for an Attribute is the value that the Attribute has when the Entity Record or Structure is first intialized. So if you, say, create a Local Variable of a certain Structure, then the initial values of the Attributes of that Structure will have the Default Value. You should never set it for an auto-increment Id, because that will have the same effect as assigning that value in the code. Which means it's ignored on a Create, but used for CreateOrUpdate or Update.

2023-01-04 05-10-52
Akshay Puri

Again Thank you Kilian, I think I am aligned now with this.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Glad I could be of help. Happy coding!

2020-09-21 11-35-56
Sachin Waghmare

Hi Akshay,

I am not sure if this can be accomplished through service studio. However, it might be the case that if default value can set from backend i.e. SQL Server or Oracle database this would be possible. I would recommend here is that set autonumber to No and you can write logic to insert the unique entity identifier with your default value following next sequences.

Thanks & Regards,

Sachin

2023-01-04 05-10-52
Akshay Puri

Thank you Sachin.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.