How to Generate Unique ID in Power Apps? [Using GUID Function]

I developed a Power Apps application for Employee Request Forms a few days ago. I was required to generate the unique ID for each request and store it in the Sharepoint list once the employee submitted the request.

The Power Apps unique ID must be generated with letters, the current date, and five digits from the GUID. For example, it would look like “Req-20240923 -2234.

In this article, I will explain how to generate a unique ID in Power Apps and how to save it in a SharePoint list with an example.

Generate Unique ID in Power Apps

In the example below, you can see I have a request form in Power Apps. Once the employee submits a request, I need to generate a unique Request ID, a combination of some letters, the current date, and five numbers from GUID.

generate unique user id in power apps

Here, I have a SharePoint list named Request Form Details that stores all the requests submitted from Power Apps. I took the Request ID field data type as a Single line of text.

how to generate unique id in power apps

Follow the steps below to generate a Unique ID.

1. In Power Apps, add the Edit Form control from the +Insert tab and connect it to the SharePoint list.

power apps generate unique id

2. To submit the form details to the SharePoint list, add a save icon and provide the formula below on its OnSelect property:

Set(myGUID,GUID());
UpdateContext(
    {
        varDigits: FirstN(
            Filter(
                Split(
                    myGUID,
                    ""
                ),
                IsNumeric(Value)
            ),
            5
        ),
        varRequestID: "Req-" & Text(
            Now(),
            "yyyymmdd"
        ) & "-" & Trim(
            Concat(
                varDigits,
                Value,
                ""
            )
        )
    }
);
If(
    Form1.Valid,
    SubmitForm(Form1) && Notify("Your Request Has Been Submitted Successfully" NotificationType.Success);
     Navigate(WelcomeScreen,ScreenTransition.CoverRight),
   // If the form is not valid
 Notify("Please Fill All The Required Fields",NotificationType.Error)
);

In the above code,

  • myGUID is a variable that contains the GUID value.
  • varDigits is a local variable that contains the first five numbers from GUID.
  • The Split function will Split the string(GUID) apart, using an empty string as the separator. This will break the string on each character.
  • The IsNumeric() function will fetch only numbers from the output of the split function.
  • Filter() function will fetch only the first five numbers from the IsNumeric() output.
  • varRequestID
  • varRequestID variable contains the unique ID, a combination of “Req” and the current date in the format of “yyyymmdd,” and then five digits from GUID that we stored in the varDigits variable.
  • Form1.Valid will check all the validations; if everything is followed, it submits the form details to the Sharepoint list and displays a success message simultaneously. If the form is not valid, then it displays an error message.
generate id power apps

Now, save and publish the app. While previewing, submit a request; you’ll see the unique Request ID in the SharePoint list.

power apps create unique id

This way, we can generate a unique ID for each request from Power Apps.

I hope you understand how to generate a unique ID from Power Apps. This approach reduces the time required to generate an ID from Power Apps instead of using the Power Automate flow.

Also, you may like:

>