How can I create unique Identifiers in my app? (UUID)

  1. i’ve search fourm, and with thunkable, we cant get IMEI, phone number, so can we create a random number (ID) and set to phone, when close app and open app again, this number (ID) wont change, can we do this ?
  2. And in my app, there too much products in colum A (google sheet), and i have textbox1, how i can search data in textbox1.text (user input data in textbox1) in colum A, if textbox1.text have on colum A and do somethings, else do something …
    Thank you.
1 Like
  1. Yes. If you create a random value and set a Stored variable to it, the device will remember the value.
1 Like

I use a roundabout way to get a unique number that won’t repeat.

I create a local table in the project and every time I need a unique number generated, I use the create row block
image

Every new row created will have the green block row id which is a unique number which I use it in my project.

device will remember tha value event i close app, turn the phone off ?

Yes. Until you uninstall the app.

1 Like


How i can store variable ID ?
i think this block always create random value and store it, so variable ID not the same ?

Don’t use local storage. When you use the set app variable block, change the app drop-down menu to stored. So it will say “set stored variable _____ to”.

Also, you don’t want to use another variable block for the variable name. Just use the “set” variable block that has the name of the variable that you initialized.

2 Likes

Thank you for your help, but i dont understand your mean “app drop-down menu” ?
Can you make me some blocks ?

Here’s a screencast of creating and using a stored variable:

https://watch.screencastify.com/v/GlBsPws9qtqZXYfSk5Wz

Note: I initially added an Else section to the If block but then realized I didn’t need it. Also, you’ll see that I check for a null value for the stored variable and set it to zero (or any starting value) if it’s null. I believe this is standard practice but I honestly don’t know why it has to be done.

1 Like


Am I doing it right ? I dont see any block to set stored variable ID to device ? when i test with component, it always a random number

No. You should not be using Local Storage blocks. Those have been discontinued.

Please refer to my video. Here’s a screenshot of the blocks from it:

The second to last block saves the random number in the stored variable. The last block displays the saved value. The thing is, if you run this more than once, it’s going to set a new value. So you may want to only set the random ID once. You can do this by saying If stored variable random ID = 0 then set stored variable random ID to random integer from 1000000 to 9999999. That way, once it’s set to a new value, it won’t ever be set again.

1 Like

Here’s a simplified version:

Test it on a mobile device by opening the app a few times. You’ll see that it sets a value and then displays that same value every time.

1 Like

thank you very much.

1 Like

Can u suggest how can i check, if stored variable have on colum A ( google sheets ) and do somethings, in kodular i can call with web1.get and check, with xthunkable, im new so hope you will help.

Hey @phamduyhoang1982nc Firebase a userID would be a solid unique identifier to use. Why not use that? It’s a secure way to login and provides a unique identifier to each signed up user per Firebase project.

Alternatively you can make a GET call to this UUID generator!

https://www.uuidtools.com/api/generate/v4

The random integer route is ok but potentially leads to more chances for duplicates than the route above. That said, the above only works when your connected to the internet so :man_shrugging:

2 Likes

alternatively, generate your own

    function new_uuid() {
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
            var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
            return v.toString(16);
        });
    }
3 Likes