cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

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

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
CarlosFigueira
Power Apps
Power Apps

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) &
"}"
Anonymous
Not applicable

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.

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.

 

Mike8
Memorable Member
Memorable Member

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)})

Anonymous
Not applicable

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. 

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.

 

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.

Hello,

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

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events that are happening this month - don't miss out!

Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Top Solution Authors
Top Kudoed Authors
Users online (2,111)