Hi folks
I have a scenario wherein I need to generate random alphanumeric numbers and store them in database.
My scenario goes in like when I create a new student and add their details the seat number should be a random alphanumeric number around 8 digits and it should get stored directly in the database whenever I click on save button.
Hi Athulya,
check out this demo, It will update new alphanumeric value everytime there is new entry and everytime there is update.
Thanks AWL!
Thank you so much for the solution
Here are possible solutions to your requirement:
1. Generate only when create (Original answer)If(Source.Id = NullIdentifier(), GeneratePassword(8, True), Source.Seat)2. Generate new every time (create and update)GeneratePassword(8, True)3. Generate every time when updateIf(Source.Id = NullIdentifier(), Source.Seat, GeneratePassword(8, True))4. Generate only on first updateIf(Source.Id <> NullIdentifier() and Source.Seat = NullTextIdentifier(), GeneratePassword(8, True), Source.Seat)
This assign is in the "StudentCreateOrUpdate" server action
Hi @Athulya Panicker
You can use GeneratePassword(Integer, Boolean) action to generate alphanumeric numbers.
You can find complete guide here.
I hope it'll help you,
Thanks
Deep
Hi I was able to generate random numbers but I couldn't save it into the db by using server actions
Hello Athulya Panicker,
So, the Generate password returns a password/integer string of length you have defined.
After that you don't need something extraordinary and unusual like you already normally do to save data on the database.
In resume, in order to save information/data on the database:
These are some links that might help you:
I also recommend you review or do the guide paths:
Including the exercises that include detailed instructions on how to do these things and much more, like bookings, employees or orders, for example.
Best regards,
Ana
Hi Athulya
I don't think there will be any problem to save it, Just make sure your entity attribute type is test in which you want to save this random generated string.
Hi @Athulya Panicker, I am adding an OML, please look to see if it helps.I have used the GeneratePassword function, as @Deepsagar Dubey suggested, to save seat directly in the database.ThanksGitansh Anand
Hi @Gitansh Anand
The solution you've sent have worked perfectly but there is a slight change in my POC now, I want to generate alphanumeric numbers when I update table. What changes should I do in the condition to achieve it?
Do you need to generate new alphanumeric numbers every time the table is updated? Will you not generate alphanumeric numbers the first time you create in the table?
Actually in my POC there are 2 buttons
1. button is to save details to the table
2. update the table while generating alphanumeric value.
Since I need to use the second button for updating the table and generating values I asked the doubt.
In your second button click action pass the actual record Id which you stored in database by clicking on first button,
Then use the GeneratePassword(Integer, Boolean) action to generate alphanumeric value and use the updateEntity action to update record in your table.
In that case, create a new action, call this action to the 2nd button, add the GeneratePassword function to update the value of Seat in the source, and then call the original action. Also remove the GeneratePassword function used in the original function.This way, the first button will work as it is (without the alphanumeric value), and the second button will first create a new alphanumeric value and then work as it is.ThanksGitansh Anand
Hello Athulya Panicker