Generate UUID field into structure, using them as key into another multiselect

Hi,

Looking a the forum, i see multiple old posts and responses that asks for an UUID linked to record, for example in a structure, as a primary key to reuse later.

I have exactly this need, as you will see in this picture.

User enter Trips, adding a manual key (id) to identify later in the Partners structure.

The blueprint is actually really simple :

  ExternalMobility:
    label: Séjour(s) de recherche à l'étranger 
    type: structure
    fields:
      role:
        label: Rôle
        type: select
        options:
          SE1: "SE - Organisateur.rice seulement"
          SE2: "SE - Participant.e seulement"
          SE3: "SE - Organisateur.rice et Participant.e"
...
      id_institution: 
        label: id
        type: text
  ExternalPartners:
    label: Partenaires
    type: structure
    fields:
      id_institution: 
        label: id de l'institution
        type: multiselect
        options:
          type: query
          query: user.Externalmobility.toStructure
          text: "{{ item.id_institution }}"
          value: "{{ item.id_institution }}"
      country:
        label: Pays
        type: text
      city:
        label: Ville
        type: text
      partners_name:
        label: Nom du Partenaire
        type: text

In this example picture, data and uuid is integrated into user.txt using a csv.

I’m now interested to generate an UUID when people create a new “Trip” (“Séjour” in French) in the ExternalMobility structure.

I see multiple paths, but perhaps there are others using V5 version of Kirby ?

  • using a user.update:after * hook that call a generate_uid() function to store into id_institution field of ExternalMobility
  • developping a new field which generate a new uid each time we create a new entry
  • using a custom Query to generate_uid() on field text if it’s possible, like * here ?
  • using store properties of fields to store an uuid ?

I also found there is a FieldUUI() but no documentation about using it .

Maybe better than updating everything using a hook would be a custom field that would allow you to generate a random string on click of a little button.

Or maybe extend a text field and add a method that generates an ID as default value. Not really sure if this will work, though.