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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Generate unique ID num...
Power Apps
Answered

Generate unique ID number when saving form (increment +1)

(1) ShareShare
ReportReport
Posted on by 118

Hi, 

I am trying to generate a unique number for each notification that is created and saved from a form. 

I want the number to start with a certain value (e.g. 1000) and by clicking on the save button the number should always be incremented by 1. The last saved number then should always be the new starting number when a new form is created. 

 

I set the following values and variable, but then the start number is always 1000. How can I manage to have the last incremented number that was generated after clicking the save button as a new start number?

 

App: 

OnStart = Set(ID; 1000)???

 

Field value:

Default = ID???

 

Save button: 

OnSelect = Set(ID; ID+1)

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    154,906 Most Valuable Professional on at

    Hi @DirkKoch ,

    If you are using SharePoint, ID is a reserved field, but I will use MyID below as an example.
    On the OnSuccess of the Form

    Patch(
     SPListName,
     {ID: Self.LastSubmit.ID},
     {
     MyID:
     First(
     Sort(
     SPListName,
     MyID,
     Descending
     )
     ).MyID + 1
     }
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • DirkKoch Profile Picture
    118 on at

     @WarrenBelz : Yes it is submitting to a SPlist. So I changed the variable to MyID as in your example. It is important that I can set the first start value manually (in this example 1000).  

    App: 

    OnStart = Set(MyID; 1000)

     

    Field value:

    Default = MyID

     

    Save button: 

    OnSelect = Set(MyID; MyID+1)

     

    Form: 
    OnSuccess: Patch(SPListName; {ID: Self.LastSubmit.ID};(MyID: First(Sort(SPListName; MyID; Descending)).MyID+1))

    For the OnSuccess formula I receive the following error message: "Invalid argument type (number), Expecting a Record value instead"

    How can I fix this? Thank you in advance!

     

  • WarrenBelz Profile Picture
    154,906 Most Valuable Professional on at

    Hi @DirkKoch ,

    Just a mis-type of bracket (now fixed - I thought you might have picked that up - although you changed one of mine, but the wrong one . . . ).

    Patch(SPListName; {ID: Self.LastSubmit.ID};{MyID: First(Sort(SPListName; MyID; Descending)).MyID+1})

  • DirkKoch Profile Picture
    118 on at

    Hi @WarrenBelz
    the syntax is now correct by changing the bracket form accordingly. Nonetheless my issue is still not solved. 

    If I use the following formulas, the start number is always 1000. But I want the start number to be the last saved  number +1. 

     

    For example: I start the app. The first notification has the number 1000.

    I create three notifications ending with number 1002. 

    So when I open the app the next time the start number should be 1003. 

     

    So the start number is not fix. It is always the last saved number from the submitted form +1.

     

    App: 

    OnStart = Set(MyID; 1000)

    Field value:

    Default = MyID

    Save button: 

    OnSelect = Set(MyID; MyID+1)

    Form: 
    OnSuccess: Patch(SPListName; {ID: Self.LastSubmit.ID};{MyID: First(Sort(SPListName; MyID; Descending)).MyID+1})

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @DirkKoch 

    Forget about the patch.  Add a card for the MyID column and make its Update property:

    First(Sort(SPListName; MyID; Descending)).MyID+1}). Then, hide the card. Sharepoint will automatically increment the MyID column when the form is saved and a user can't change it. 

  • DirkKoch Profile Picture
    118 on at

    Hi @Drrickryp 
    Thanks for your support. That works for SP if you start with number 1. 

    The problem for me is that I need to start with a certain number (e.g. 1000 and not 1) and I need to show the next free available number within my Powerapps form (-> DataCardValue (Default = ?))

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @DirkKoch 

    Add a dummy record to your sharepoint list with MyID = 1000

  • DirkKoch Profile Picture
    118 on at

    @Drrickryp 
    We are getting close :-). Only issue left is to show the next available number in the DataCardValue field and set the Default value accordingly. Is that possible?
    Sorry for bothering! I am just getting started!

  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @DirkKoch 

    It isn't necessary as the Update property of the card is the value that will be saved.  If you must,  you can set the Default of the DataCardValue control:  First(Sort(SPListName; MyID; Descending)).MyID+1 but I would disable the card or hide it.  You don't want the user to change it.

    Developers-vs-users.jpg

     

  • DirkKoch Profile Picture
    118 on at

    @Drrickryp Thanks a lot. Greatly appreciated! In order to avoid the editing from users I will put the Displaymode to View, that should do. 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 528

#2
WarrenBelz Profile Picture

WarrenBelz 426 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 306

Last 30 days Overall leaderboard