# How to create UUIDs for new entities?

**URL:** <https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041>\
**Category:** API & Programming\
**Created:** [September 19, 2021, 10:03pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041 "2021-09-19T22:03:04Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Blais](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matt_blais/32/1464_2.png) [@Matt\_Blais](https://community.fibery.io/u/Matt_Blais)\
**Post date:** [September 19, 2021, 10:03pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/1 "2021-09-19T22:03:04Z")

</div>

In a Button Script, I am going to duplicate an entity, and also duplicate the entities in one of its collections (a partial “deep clone”).

As suggested in the [API examples](https://api.fibery.io/?shell#create-entity), it would be useful to pre-set the `fibery/id`'s of some of these clones I’m going to create, to simplify adding them to the new parent’s collection.

**How can I generate a UUID in a script?**

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [September 20, 2021, 6:09am UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/2 "2021-09-20T06:09:11Z")

</div>

Not sure why you want to set the ID, as opposed to just creating an entity and reading its ID, but you can always just use a random number for a part of the UUID if you want to create your own each time:  
`Math.floor(Math.random * 10000)`  
should get you an integer between 0 and 9999.  
You will probably need to make use of `.toString()` as well

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [September 20, 2021, 11:45am UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/3 "2021-09-20T11:45:31Z")

</div>

```auto
const parent = await fibery.createEntity('AppName/ParentTypeName', { 'name': 'P' })
const child = await fibery.createEntity('AppName/ChildTypeName', { 'name': 'C' })
await fibery.addCollectionItem('AppName/ParentTypeName',parent['Id'],'ChildFieldName',child['Id'])

```

Any use?

---

<div class="post-metadata">

**Author:** ![Matt\_Blais](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matt_blais/32/1464_2.png) [@Matt\_Blais](https://community.fibery.io/u/Matt_Blais)\
**Post date:** [September 20, 2021, 3:30pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/4 "2021-09-20T15:30:27Z")

</div>

So, is there not a strict requirement that the `fibery/id` field contains a “real” UUID (mac address and timestamp)?  
– –

> [@Chr1sG](#):
>
> Not sure why you want to set the ID, as opposed to just creating an entity and reading its ID

I have noticed it can be a lot more efficient to lump all the entity creations/updates into as few API calls as possible, and execute them under under a single `Promise.all()`, as opposed to a series of `await`s.

If I can set and use the `fibery/id`s of the new entities I am creating (cloning) before creating them, then I will not need to read them back after creation = big time savings.

_[“Setting fibery/id is optional and might be useful for working with Entity right after creation.”](https://api.fibery.io/?shell#create-entity)_

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [September 20, 2021, 3:42pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/5 "2021-09-20T15:42:10Z")

</div>

> [@Matt\_Blais](#):
>
> So, is there not a strict requirement that the `fibery/id` field contains a “real” UUID (mac address and timestamp)?

As far as I know, any unique identifier of the correct format works, but I’ll double-check.

> [@Matt\_Blais](#):
>
> it can be a lot more efficient to lump all the entity creations/updates into as few API calls

Makes sense. I hadn’t imagined that this process was slowing you down, but it’s a good point.

---

<div class="post-metadata">

**Author:** ![Viktar\_Zhuk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/viktar_zhuk/32/1934_2.png) [@Viktar\_Zhuk](https://community.fibery.io/u/Viktar_Zhuk)\
**Post date:** [September 20, 2021, 4:13pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/6 "2021-09-20T16:13:03Z")

</div>

As far as I know there is no utility method to generated uuid for now. It would be nice to have such method, will propose that to maintainer. Meanwhile, you may try the following snippet

```auto
function uuidv4() {
    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);
    });
}

```

It is not so universally unique but would be enough for your use case.  
All credits to [stackoverflow](https://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid)

---

<div class="post-metadata">

**Author:** ![Matt\_Blais](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matt_blais/32/1464_2.png) [@Matt\_Blais](https://community.fibery.io/u/Matt_Blais)\
**Post date:** [September 20, 2021, 7:47pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/7 "2021-09-20T19:47:31Z")

</div>

Thanks @Viktar_Zhuk – I believe it requires **UUID v1**.

---

<div class="post-metadata">

**Author:** ![Viktar\_Zhuk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/viktar_zhuk/32/1934_2.png) [@Viktar\_Zhuk](https://community.fibery.io/u/Viktar_Zhuk)\
**Post date:** [September 20, 2021, 7:59pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/8 "2021-09-20T19:59:08Z")

</div>

You must not. We are using uuid v4 all over the place.

---

<div class="post-metadata">

**Author:** ![Matt\_Blais](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matt_blais/32/1464_2.png) [@Matt\_Blais](https://community.fibery.io/u/Matt_Blais)\
**Post date:** [September 20, 2021, 8:50pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/9 "2021-09-20T20:50:04Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/e/e3175c9b1d34d57c78470827aa5c8b826fb7bd01.png)

---

<div class="post-metadata">

**Author:** ![Viktar\_Zhuk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/viktar_zhuk/32/1934_2.png) [@Viktar\_Zhuk](https://community.fibery.io/u/Viktar_Zhuk)\
**Post date:** [September 20, 2021, 9:09pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/10 "2021-09-20T21:09:37Z")

</div>

I’ve double checked server side source code it accepts any UUID whether it v1 or v4. I can guarantee that v4 will be supported in long term cause we use this version in majority cases. In any case, there is no way to generate UUID value beforehand using our platform. So you may stick to own implementation or abandon the idea.

---

<div class="post-metadata">

**Author:** ![Sergey\_Truhtanov](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/sergey_truhtanov/32/13986_2.png) [@Sergey\_Truhtanov](https://community.fibery.io/u/Sergey_Truhtanov)\
**Post date:** [September 22, 2021, 5:52pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/11 "2021-09-22T17:52:57Z")

</div>

You can use this code now:

```auto
const utils = context.getService('utils');
console.log(utils.uuid());

```

---

<div class="post-metadata">

**Author:** ![Maximilian\_Breckbill](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/maximilian_breckbill/32/5080_2.png) [@Maximilian\_Breckbill](https://community.fibery.io/u/Maximilian_Breckbill)\
**Post date:** [May 23, 2022, 3:12pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/12 "2022-05-23T15:12:16Z")

</div>

Hello all - I don’t know script, but would like to have a column in my Database which automatically generates a UUID for each Row (aka Entity).

Can anyone explain how to set this up in Fibery so a UUID would be created for each entity and added to a “UUID” titled column?

Much appreciated :).

> [@Sergey\_Truhtanov](#):
>
> ```auto
> const utils = context.getService('utils');
> console.log(utils.uuid());
> 
> ```

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [May 24, 2022, 12:26pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/13 "2022-05-24T12:26:08Z")

</div>

See here:

> [@What is the best way to get the ID of drop down options?](https://community.fibery.io/t/what-is-the-best-way-to-get-the-id-of-drop-down-options/2719/6):
>
> I guess you’ve probably have thought of it, but you could make text field (called UUID) and define a scheduled automation to get the ID. Then just ‘Run now’ to populate all of them at once:

You could run the automation when an entity is created if that was preferable.

---

<div class="post-metadata">

**Author:** ![Matt\_Blais](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matt_blais/32/1464_2.png) [@Matt\_Blais](https://community.fibery.io/u/Matt_Blais)\
**Post date:** [May 24, 2022, 3:01pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/14 "2022-05-24T15:01:30Z")

</div>

> [@Maximilian\_Breckbill](#):
>
> would like to have a column in my Database which automatically generates a UUID for each Row (aka Entity)

The entity Id is already already what you describe. Do you need another Id field for each entity? Why would you need two unique Ids?

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [May 24, 2022, 4:13pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/15 "2022-05-24T16:13:17Z")

</div>

Thanks @Matt_Blais  
Indeed, the public id for an entity is unique (within a database) so unless you need _the_ UUID (which is used in the backend, for APIs/scripting etc.) it should suffice.

---

<div class="post-metadata">

**Author:** ![Matt\_Blais](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matt_blais/32/1464_2.png) [@Matt\_Blais](https://community.fibery.io/u/Matt_Blais)\
**Post date:** [May 24, 2022, 6:09pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/16 "2022-05-24T18:09:36Z")

</div>

OK, I see that the “real” (globally unique) entity Id is not accessible from the Fibery front end. So perhaps what is needed is a script that simply copies this “back end” Id to a string field where it can be seen in a table. You could do that upon entity creation.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [May 24, 2022, 6:30pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/17 "2022-05-24T18:30:04Z")

</div>

Yep, that’s what the linked to topic covers. It can be run on creation.  
Except to say that strictly speaking the UUID is not necessarily globally unique. It is unique within a given workspace/database.

---

<div class="post-metadata">

**Author:** ![myg\_ge](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/myg_ge/32/12457_2.png) [@myg\_ge](https://community.fibery.io/u/myg_ge)\
**Post date:** [August 28, 2025, 7:46pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/18 "2025-08-28T19:46:35Z")

</div>

I’ve figured I can use Fibery Rule with AI to generate UUID for every relevant record. The only downside this would eat my tokens.

Other than that you can use the following prompt:

`Generate a single, unique random number in UUID version 4 format. Output only the UUID string, with no explanation, no additional text, and no code blocks. Make sure it follows the standard hyphen-separated hexadecimal pattern: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, where each ‘x’ is a hexadecimal digit (0-9 or a-f).`

This one might be a solution if scripting isn’t supported by your plan.

---

<div class="post-metadata">

**Author:** ![RonMakesSystems](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/ronmakessystems/32/14122_2.png) [@RonMakesSystems](https://community.fibery.io/u/RonMakesSystems)\
**Post date:** [August 28, 2025, 11:52pm UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/19 "2025-08-28T23:52:23Z")

</div>

I don’t know how great of an idea this is… AI is just predicting the next possible letter. There’s I think quite a high chance that it will return similar values when asked multiple times. It’s not properly a random UUID…

---

<div class="post-metadata">

**Author:** ![myg\_ge](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/myg_ge/32/12457_2.png) [@myg\_ge](https://community.fibery.io/u/myg_ge)\
**Post date:** [August 29, 2025, 5:39am UTC](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041/20 "2025-08-29T05:39:13Z")

</div>

Hmm. Thanks for this one. Then I may need another rule to verify uniqueness… hate this kind of stuff - better having a standard uuid field type available

[Next page](https://community.fibery.io/t/how-to-create-uuids-for-new-entities/2041.md?page=2)
