cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
stvcdms
Level 8

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 Staff GregLi
Power Apps Staff

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

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) &
"}"
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.

Cheve
Level: Powered On

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.

 

Super User
Super User

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

stvcdms
Level 8

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 Staff GregLi
Power Apps Staff

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

adrianivanov
Level: Power Up

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.

Super User
Super User

Re: Create a GUID

Hello,

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

Helpful resources

Announcements
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

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