I want to generate password in sequence like 000001, 000002 in sequence. How Can I achieve that?
Hello Kapil,
In this case you will need to generate this sequence and save it to table and every new record you will need to get max (latest) sequence then add one to it.
- While your table is still empty so first sequence will be 000001
- For second record when you get max sequence it will be 000001 and then convert this sequence to integer (result will be 1) and add 1 so final result here will be 2
- Check length of integer value you got if its length 1 then add five zeros. If its two digits add 4 zeros and so on.
- Finally save new record with new sequence
Hii @Mostafa Othman,
I got what you are saying. But Is it possible that I set default value as 000001 and then get max value and then increment it by 1.
You need to add a sequence number for every record
Then you can use FormatText() as shown:
FormatText(GetFinancialDetails.List.Current.FinancialDetails.Sequence,6,6,True,0)
Hii @Shubham Doshi,
thanks will try this.
Hi @Shubham Doshi
It is showing 000000 all the time and is not incrementing. How to add the increment function.
You can either save sequence for every record in database itself or you can simply store the sequence in Site Properties and increment it every time you create record.
You can increment site property in same logic where you are creating the record.
Let me know if you need demo for better understanding
Hi Shubham,
Changing the value of a site property in code is an anti-pattern, something you should never do. Site properties are cached, and updating them invalidates that cache, not only in the module itself but in all consumers as well. This comes with a hefty performance penalty!
Hi Kapil,
You do realize that if you generate a "password" that is predictable, it's not a very good password? (And in fact, is a security nightmare.)
Hi @Kilian Hekhuis,
Actually I am Creating Application Number of a form which is submitted by user.
I am using generate password function for creating that application number but it should generate in sequence like 000001. It is for learning purpose only.
warm regards,
kapil
But the generate password action generates passwords, not sequence numbers. So why did you use it in the first place?
I was trying random numbers before for generating application number but then I thought it should be in sequence. So I decided to change that.
Ah, that explains the confusion :).
Like others have said, you need some place to store the last used sequence number, so I'd create an Entity for that, with a single record for this sequence. When you want to create a new application number, you read the record (use a GetXxxForUpdate instead of a normal Get or an aggregate, to avoid duplicate numbers being issued if two users try to generate an application at the same time!), increment it, save it and return the new number (of course, all this should be abstracted in an action!).
Thank you @Kilian Hekhuis for explaining in detail.
I will imply that logic.
Warm Regards,
Kapil