cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
T_A_M
Helper IV
Helper IV

Generating a random invoice number

Hello all -

 

I need to generate a completely random invoice number in an app, and I've found a formula that works:

 

Right(Text(Rand()*10),3)&"-"&Right(Text(Rand()*10),3)

 

However, I'm not sure how to keep the number from recalculating every time my form is submitted. Once this number is generated it needs to remain associated with its item, and never change.

 

Any ideas would be greatly appreciated. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Drrickryp
Super User
Super User

@T_A_M 

No need to use a variable. Set the Text property of the InvoiceNumber control to 

Coalesce(Parent.Default,Right(Text(Rand()*10),3)&"-"&Right(Text(Rand()*10),3)), When the form is in new mode, the Parent.Default will be blank and then your formula will generate a random invoice number.  When the form is in edit mode, the already assigned random invoice number will be the Parent.Default and a new number will not be generated.  I would set the Display property of the card containing the invoice number to disabled to prevent users from changing it or trying to assign one. 

View solution in original post

3 REPLIES 3
Silvester
Skilled Sharer
Skilled Sharer

Hi @T_A_M ,
Kindly try setting it up the value in a variable 

Set(VarInvoiCceNum, Right(Text(Rand()*10),3)&"-"&Right(Text(Rand()*10),3))

You can attach the variable to the record while submitting the form.

Drrickryp
Super User
Super User

@T_A_M 

No need to use a variable. Set the Text property of the InvoiceNumber control to 

Coalesce(Parent.Default,Right(Text(Rand()*10),3)&"-"&Right(Text(Rand()*10),3)), When the form is in new mode, the Parent.Default will be blank and then your formula will generate a random invoice number.  When the form is in edit mode, the already assigned random invoice number will be the Parent.Default and a new number will not be generated.  I would set the Display property of the card containing the invoice number to disabled to prevent users from changing it or trying to assign one. 

Thank you! That worked perfectly.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (2,679)