# Uniquely identify set entries

**URL:** <https://discourse.getcockpit.com/t/uniquely-identify-set-entries/2702>\
**Category:** Support\
**Created:** [February 13, 2023, 9:08pm UTC](https://discourse.getcockpit.com/t/uniquely-identify-set-entries/2702 "2023-02-13T21:08:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rew](https://avatars.discourse-cdn.com/v4/letter/r/ed655f/32.png) [@rew](https://discourse.getcockpit.com/u/rew)\
**Post date:** [February 13, 2023, 9:08pm UTC](https://discourse.getcockpit.com/t/uniquely-identify-set-entries/2702/1 "2023-02-13T21:08:19Z")

</div>

I have a `Tree` model that’s a list of document groups/categories. One of the subfields is a `Set`, which contains the documents inside the group. What I want is a page that lists all the groups, each with a list of the documents it contains as links to view the document on another page. Further, I need the document links to be permalinks, as they’ll also be posted elsewhere.

Building it, everything was going great until I hit the document links. It seems `Set` entries don’t have their own `_id` nor any other way that I can see to reliably identify a particular `Set` entry from its peers (given array position is mutable). Without that, I’m not sure how to build the links, since I need to pass a parameter to the document page identifying which doc to show.

I guess my first question is: am I missing something? Is there a way to identify `Set` entries among peers that I overlooked? Maybe a setting I can toggle that would be helpful? Or some other solution?

As a workaround, I think I can add an extra field to the document items to serve as an ID field. It’s a little ugly but would work if I can get it reliably populated. Which leads to these questions:

- Can I provide some magic dust in an options or meta JSON field on the `Set` itself, on the items, or on the ID field, that would auto-populate the field with a calculated hash or similar?

- Reading a bit, it sounds like Cockpit is extensible enough that I can build an addon to do the population, or perhaps to extend the `Set` field as a new field that includes an `_id` value. But I have no idea how to get started – I’m just getting started with Cockpit itself, and the docs don’t have anything about addons. I’ve been looking around, but about everything I find is for v1, and I understand v2 was a major update with significant, incompatible changes. I’m very comfortable with PHP, so that’s not a hurdle, but a clean, secure starting point would be extremely helpful.

On a closing note, if I’m not overlooking how to enable an an `_id` field, I’d like to propose this addition as a feature request. Along with plenty of use cases similar to my immediate one, I suspect this would be extremely helpful in lots of ops use-cases, such as backup or data syncing solutions.

---

<div class="post-metadata">

**Author:** ![rew](https://avatars.discourse-cdn.com/v4/letter/r/ed655f/32.png) [@rew](https://discourse.getcockpit.com/u/rew)\
**Post date:** [February 18, 2023, 7:35pm UTC](https://discourse.getcockpit.com/t/uniquely-identify-set-entries/2702/2 "2023-02-18T19:35:54Z")

</div>

As a quick follow-up, I tried to do something like this:

```auto
default: crypto.getRandomValues(new Uint32Array(3)).join('')

```

on a text field, but the editor says the JSON is invalid starting with the ‘c’ in there, and then it tosses the change when I save. In fact, it seems to reject anything other than a simple constant value. I hoped the JSON string was ultimately handed off to the browser as a JavaScript object, but I guess that’s not the way it works.

Any other ideas?

---

<div class="post-metadata">

**Author:** ![artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artur/32/4_2.png) [@artur](https://discourse.getcockpit.com/u/artur)\
**Post date:** [February 21, 2023, 11:53pm UTC](https://discourse.getcockpit.com/t/uniquely-identify-set-entries/2702/3 "2023-02-21T23:53:04Z")

</div>

I would recommend to create and register a custom field via a custom addon which generates a unique id on init.
