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.
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 likeroll 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 RegardsTousif Khan
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
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
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.
Hello Tousif
It is working just how I wanted. Thank you so much.
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