web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Create a random number...
Power Apps
Unanswered

Create a random number that does not alredy exists in SharePoint list without Flow.

(0) ShareShare
ReportReport
Posted on by

Hi Everyone, 

 

I'm building a post-registration form and need to assign a custom, unique ID to each list item using YYYY.<number>. 

 

Initially I built this logic using Flow but since our license results in a 5minute delay I need to figure out another way. 

 

One way to assign a custom ID would be to create a random number on the form (text label) between 0-999999. I however need to check if this value does not already exist in the list and if it does, create a new number.

 

Is this possible without using Flow? 

 

Thanks!

Categories:
I have the same question (0)
  • BCLS776 Profile Picture
    8,994 Moderator on at

    Power Apps, as you've probably figured out, does not have a looping function with an exit condition, which is what you would use to compare generate IDs until a unique one comes up. A couple of ways around this:

    1. I frequently use the Now() function to generate a timestamp to work into a unique ID - that's typically unique enough
    2. You can use an If() statement to have a couple (or more when you use nested If()s) of tries to generate a truly unique random number. It is unlikely, but not impossible, that you'll end up with a duplicated random number that way.

    Hope that helps,

    Bryan

  • rubin_boer Profile Picture
    4,841 Super User 2024 Season 1 on at

    hi there @Anonymous simply curious why do you need the unique id to be random? will the ID column in SharePoint not meet your need?

     

    as you do not have a loop function in power apps you could use a timer control with the randbetween function to generate this. 

     

    for e.g. (data = {1,2,4,5,9})

    Add timer

    • duration =  100
    • auto start = true
    • OnTimerStart = Set(__RandBetweenB, RandBetween(1,10))
    • Repeat = __RandBetween in data.Value

     

    With the above the timer will be true when the value in data matches a generated number and it will stop when a random number is generated which is not in the data.

     

    When the number is generated, the time is switched off at 6

    rubin_boer_0-1640878990317.png

     

    Hope it helps,

    R

     

     

  • Community Power Platform Member Profile Picture
    on at

    Hi Everyone, 

     

    My users require(d) a list of unique numbers per year, not over just the complete set. Ideally even with numbering, starting every new year at 1.

     

    Now I tried to fix that with a flow based on the 'item created', but the delay is too long. 

     

    Then I opted for the option to combine YYYY with SharePoint's ID in a calculated column, but it turned out that SharePoint calculates the column before giving it an ID, so that didn't work either. 

     

    Now I have just made it so that whenever the user opens the form in New mode, a direct Flow is triggered returning a unique ID based on YYYY & random number between 0 and 999999. That's probably the best solution I can come up with to work around the delay and (!) not calculating a number that can be calculated by two users who would work simultaneously.

     

    Thanks for the input though!

  • hemrhk Profile Picture
    361 on at

    You could have used the timestamp with Date, Text(Now(),"yyyymmddhhmmssfff")

  • CodrutFt Profile Picture
    46 on at

    Hei, I am not sure if this will solve your problem because you said you might want to reset the numbers every year. 

    What I found also useful is in generating either a random number or a unique number is that you can work with the previously added item in that sharepoint list. 

     

    For example i had to create a 5 digits unique number for every line that will further go in a more complicated project number. 

    To get a number like that i used Text(Last('yourSPListName').ID)+10000.

     

    I leave this here, because maybe it will be useful for other people. 

     

    Cheers.

  • chairat Profile Picture
    64 on at

    Thank you so much. 

  • chairat Profile Picture
    64 on at

    Your solution is the best ever.  Thank you very much @CodrutFt   All the best to you and family.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard