450
Views
6
Comments
Solved
Auto Increment Value
Application Type
Reactive
Service Studio Version
11.53.41 (Build 62020)

Hi Everyone

I have a scenario wherein I need to auto increment an attribute "Roll No" in such a way that:

1. Whenever I will add a "roll no" e.g. 101 and save it. Then the next time when I am trying to add a new roll no, then the input box should display the "roll no" as e.g. 102 and I should be only typing other required details in the form. And the roll no as well as other details should get saved in the db.


I am also uploading my oml file along with it.

IdAutonumber.oml
2023-10-21 19-42-11
Tousif Khan
Champion
Solution

Hello

I want to know whether your roll number will always be in incremental order, and it will always be in a sequence, I mean if you enter 1, the next will always be 2,3,4,5.....

if this is the case you can fetch the data from the aggregate where you are saving the roll number and apply the aggregate function max, it will return you the max roll number in your aggregate,

then you can take an assignment and on the assignment, you can use something like
roll number = (max_rollnumberfromaggregate) + 1

I have also checked your oml, in order tofind the maximum number from your aggregate you need to change the data type of your Roll number attribute to long integer or integer.

Ihave also updated your oml with the same have a look to attach oml

Sample

I hope this helps

Best Regards
Tousif Khan

IdAutonumber_updated.oml
2022-08-23 08-18-03
Athulya Panicker

Hi Tousif

No My value would never be in a sequence. It should be like the current highest roll number in the table + 1

My roll no column can be like (e.g. 202  or anything random ) then if that's the highest value then next time input should display as 203

2023-10-21 19-42-11
Tousif Khan
Champion
Solution

I have updated my comment Check the sample attach, I did the logic according to the max rollnumer in a table.
Check the oml attached

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

Be aware that this works fine in a single-user environment, but in case multiple users access the application at the same time, you can get duplicate numbers, in case both users execute the query at the same time. If it doesn't happen that often, you could suffice with checking when you safe (ideally put a unique index on the attribute so you know for sure there will never be duplicates), but if you have a lot of users accessing the screen at the same time, you will need a different strategy, e.g. having the sequence number in a different entity, and use a GetForUpdate entity action, increase the number and save it, then pass it to the caller. 

2022-08-23 08-18-03
Athulya Panicker

Hello Tousif 

It is working just how I wanted. Thank you so much. 

2023-10-21 19-42-11
Tousif Khan
Champion
Solution

I have updated my comment Check the sample attach, I did the logic according to the max rollnumer in a table.
Check the oml attached

2023-10-21 19-42-11
Tousif Khan
Champion
Solution

Hello

I want to know whether your roll number will always be in incremental order, and it will always be in a sequence, I mean if you enter 1, the next will always be 2,3,4,5.....

if this is the case you can fetch the data from the aggregate where you are saving the roll number and apply the aggregate function max, it will return you the max roll number in your aggregate,

then you can take an assignment and on the assignment, you can use something like
roll number = (max_rollnumberfromaggregate) + 1

I have also checked your oml, in order tofind the maximum number from your aggregate you need to change the data type of your Roll number attribute to long integer or integer.

Ihave also updated your oml with the same have a look to attach oml

Sample

I hope this helps

Best Regards
Tousif Khan

IdAutonumber_updated.oml
2022-08-23 08-18-03
Athulya Panicker

Hi Tousif

No My value would never be in a sequence. It should be like the current highest roll number in the table + 1

My roll no column can be like (e.g. 202  or anything random ) then if that's the highest value then next time input should display as 203

2023-10-21 19-42-11
Tousif Khan
Champion
Solution

I have updated my comment Check the sample attach, I did the logic according to the max rollnumer in a table.
Check the oml attached

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

Be aware that this works fine in a single-user environment, but in case multiple users access the application at the same time, you can get duplicate numbers, in case both users execute the query at the same time. If it doesn't happen that often, you could suffice with checking when you safe (ideally put a unique index on the attribute so you know for sure there will never be duplicates), but if you have a lot of users accessing the screen at the same time, you will need a different strategy, e.g. having the sequence number in a different entity, and use a GetForUpdate entity action, increase the number and save it, then pass it to the caller. 

2022-08-23 08-18-03
Athulya Panicker

Hello Tousif 

It is working just how I wanted. Thank you so much. 

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

Hello Athulya,

You can set the initial value as 100 for the first time and then make logic to increment it by one and save it into the entity as 101. In the next time you can fetch the last maximum value from entity and increment it by 1 so it will be 102 and the same you can display on the screen. You can use screen onready event to fetch the last value and then to increment it by 1, so once screen get rendered fully it the text box will show the new roll number.

Thanks,

Sachin 

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