Business scenario:
In my App, I need to generate an account number dynamically also I should ensure that it is not part of the inventory/DB.
Solution:
Use the Math function Random to generate a number and append that number to a prefix as per the business need. Also, do a lookup on the inventory / DB to ensure that ID is not part of the system before.
Implementation:
Create a text box / a label on the screen and use the below formula to show the Account-ID dynamically.
"Acc-"&Round(Rand()*1000000,0)
In the above formula Rand() will give a value in fractions of 12 decimal, but I want to get the value with 6 digit number only. So, I have multiplied the result by 1million. After the multiplication, I don't need the decimal anymore so I have rounded the value to 0. This will give me only the 6 digits numeric value.
Now once I get the number I am appending it to "Acc" (you can change it as per your business needs) to make the account number in mode readable format.
Now that we got the number while adding the entry in the Data source use the below look up and ensure that the number is not duplicated.
If(IsBalnk(Lookup(sharepointlistname, columnname=Textbox.Text)),Patch(SPListName,Record),Notify("Account number duplicate");
Microsoft documentation on Rand function
Hope this helps!
Happy learning in Power Apps.!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.