cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate III
Advocate III

Create a GUID

Hey,

 

Is there any way to create a GUID with PowerApps? I am refering to making one in through the app for setting in a datasource.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Power Apps
Power Apps

Re: Create a GUID

We have added a function that returns new GUIDs.  Simply call GUID() with no arguments.  More information is available in the reference docs.

 

As the docs describe, we don't yet support reading/writing GUIDs as a proper GUID data type from CDS or SQL yet, but that is coming.  You still have to interact with databases with GUIDs stored in strings for the time being.

 

View solution in original post

8 REPLIES 8
Highlighted
Power Apps
Power Apps

Re: Create a GUID

Not using a single function, but you can combine a few functions (Mid, Rand, RoundDown) to accomplish that as shown below. I don't know how cryptographically strong this method is, though, so I wouldn't recommend it in high-security scenarios. If all you want is to set an id for an element, that should be ok.

"{" &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    "-" &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    "-" &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    "-" &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    "-" &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
    Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
"}"
Highlighted
Anonymous
Not applicable

Re: Create a GUID

Thanks for the solution

 

I've created an Idea for PowerApps team

 

https://powerusers.microsoft.com/t5/PowerApps-Ideas/Create-a-GUID/idi-p/31673#M1981

 

Seems to me to be a fairly useful function to have.

Highlighted
Advocate I
Advocate I

Re: Create a GUID

This is what I use for unique IDs with an Excel data source:

 

ID: User().Email & "_" & Text( DateDiff( Date(2010;1;1); Now(); Seconds)  )

* I use ";" as separator in my language, maybe you need to use ","

 

I got a very long id, but it depends of user and time. I use seconds, because it is almost imposible for the same user to create two record in a second, but you can use Milliseconds instead.

 

I also remove the @ part of email and convertit to lower case to get shorter ids and you can include a letter at the begining to identify the table.

 

Hope this helps.

 

Highlighted
Solution Sage
Solution Sage

Re: Create a GUID

Hello everyone,

OnStart of the application:

ClearCollect(ColForAllCounter,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36);

 

And as a column (GUID) in a collection you can add this:

GUID:Concat(ForAll(ColForAllCounter,If(Value=9||Value=14||Value=19||Value=24,"-",Switch(Mod(RoundUp(Value(Right(Text(Rand()),8)),0),16),0,"0",1,"1",2,"2",3,"3",4,"4",5,"5",6,"6",7,"7",8,"8",9,"9",10,"a",11,"b",12,"c",13,"d",14,"e",15,"f"))),Value)

Example:

Collect(Collection1,
{text:"A",
GUID:Concat(ForAll(ColForAllCounter,If(Value=9||Value=14||Value=19||Value=24,"-",Switch(Mod(RoundUp(Value(Right(Text(Rand()),8)),0),16),0,"0",1,"1",2,"2",3,"3",4,"4",5,"5",6,"6",7,"7",8,"8",9,"9",10,"a",11,"b",12,"c",13,"d",14,"e",15,"f"))),Value)})

Highlighted
Advocate III
Advocate III

Re: Create a GUID

A self-udpate on this. It's now possible to just generate a GUID with Flow using a function. This has replaced the other in PowerApps methods we use. 

Highlighted
Power Apps
Power Apps

Re: Create a GUID

We have added a function that returns new GUIDs.  Simply call GUID() with no arguments.  More information is available in the reference docs.

 

As the docs describe, we don't yet support reading/writing GUIDs as a proper GUID data type from CDS or SQL yet, but that is coming.  You still have to interact with databases with GUIDs stored in strings for the time being.

 

View solution in original post

Highlighted
New Member

Re: Create a GUID

I've tried using GUID() with no arguments in a Default Value for a "Primary Name" field of a a table in CDS, and it won't work! 

Default = If(ThisItem.cr81c_primaryname="";GUID();ThisItem.cr81c_primaryname)

It shows nothing.

 

--- Sorry, it actually shows th GUID if I only put GUID() in the Default.

Now I guess my problem is detecting if the field is empty.

Highlighted
Solution Sage
Solution Sage

Re: Create a GUID

Hello,

You can try If(IsBlank(ThisItem.cr81c_primaryname);GUID();ThisItem.cr81c_primaryname)

Helpful resources

Announcements
Check this Out

Announcing

Class of 2020- Season 2

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (8,115)