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 Apps
Unanswered

Generate Unique ID

(0) ShareShare
ReportReport
Posted on by 6

Hi,

 

I am building application on PowerApps with DataSource SharePoint list. I am trying to generate unique ID which containing letters and number such as "CRR-ZTT-2023-0000" the first two will be fixed then the year the last random number.

 

Only this field will be generated if the user is creating new forum if it is on view mode not.

 

if(EditForm1.Mode = FormMode.New, , Parent. Default) " something like this.

 

any advice?

 

 

 

 

 

Categories:
I have the same question (0)
  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @Taghreeddb_96,

     

    You could achieve this by using the hardcoded text + year + number based on the amount of records with that initial prefix (CRR-ZTT-2023).

    On the OnVisible of the screen save the first part of the code (without the number) to a variable:

     

    Set(
     varStartCode,
     $"CRR-ZTT-{Year(Now())}"
    )

     

    The Default property of the text field (DataCardValue control) would have the following code:

     

    if(
     EditForm1.Mode = FormMode.New,
     //Change Listname and CodeColumn to the correct values
     $"{varStartCode}-{Text(CountRows(Filter(LISTNAME,StartsWith(CODECOLUMN, varStartCode))),"0000")}", 
     Parent. Default
    )

     

    Please do keep in mind that CountRows() cannot return a number higher than 2000 - so the string will be unique up to 2000 records with the 'CRR-ZTT-2023' as first part of their unique code.

     

    If this solves your question, would you be so kind as to accept it as a solution.

    Thanks!

  • mmollet Profile Picture
    3,187 on at

    Sharepoint by dafault generates a unique ID and you could use this as well. You could patch everything except this value first with: 

    ClearCollect(currentItem, Defaults(SPListName), Patch everything but the unique ID here);

    This will execute the patch statement and then store that item/row in a collection called ListName (or whatever you call it). You can then execute a second patch statement that uses First(currentItem).ID as the unique number for your identifier. For example your second patch statement could look something like:

    Patch(SPListName, ID = First(currentItem).ID, {YourColHere: "CRR-ZTT-" & Year(Now()) & "-" & Text(First(currentItem).ID, "0000")})

    Im not 100% sure on the "0000" part as you can use 0's and #'s to get your desired result.

  • Taghreeddb_96 Profile Picture
    6 on at

    I keep on receiving this error, is there any other function can match my requirement? 

    f1.PNG
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @Taghreeddb_96

    Instead of a clunky If(Formmode..

    Use

    Coalesce(Parent.Default, your unique ID formula) since Parent.Default is always blank in new forms

  • Taghreeddb_96 Profile Picture
    6 on at

    sorry, what did you mean by codecolumn target store Colum on SharePoint? or text input for this id on powerapps?

  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @Taghreeddb_96,

     

    The code column refers to the SharePoint column where the unique ID is stored (CRR-ZTT-2023-0000). We need that column, because we want to count how many rows start with the first part - meaning CRR-ZTT-2023. This count is needed to add the correct ascending number at the end.

     

    The Delegation warning is to be expected, since CountRows cannot 'count' more than 2000 records.

     

    As long as the filter does not return more than 2000 records, you should be fine. In practice this would mean, that you cannot have more than 2000 unique codes starting with 'CRR-ZTT-2023'. Should this be the case, you might have to make the unique ID more specific e.g. 'CRR-ZTT-YEAR-MONTH-0000'.

     

    I hope this helps!

  • Taghreeddb_96 Profile Picture
    6 on at

    HELLO, i implement the same solution " the warning message about the delegation for count function appear" and the value is not start generated automatically once the app started. the information stored on SharePoint with empty id value.

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 April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 915

#2
Valantis Profile Picture

Valantis 571

#3
11manish Profile Picture

11manish 457

Last 30 days Overall leaderboard