Skip to main content
Version: Next

Key and Label Scripts

Every entity has a key — its unique, readable identifier within its type — and a label, the name shown in headers, tables and the graph. Both can be computed by a Lua script on the entity type:

ScriptComputesExample
Key Scriptthe key of each entityA customer number used as key
Label Scriptthe display name of each entityJulius-Hatry-Str. 1 for an Address (street and house number)

Without a label script, the key is shown as the label. The language reference with more examples is in Lua Scripting.

Edit a Script​

  1. Open the entity type, for example Address, on the tab Data Sheet.
  2. The fields Key Script and Label Script show the first line of the script; hover over it to see the whole script.
  3. Click next to the field. The dialog Script editor opens in the middle of the screen:
    • Syntax highlighting for Lua (Language is always Lua).
    • Autocomplete for self.properties.* and self.relationships.*.
    • The AI Low Code Generator next to it: ask questions about the script in the field Ask about this script…. Code blocks in its answers can be taken over into the editor with Apply.
  4. Write the script and close the editor with ✕. The script is saved when the editor closes.

Script editor The script editor for the label script of Address

To remove a script, hover over the field and click Clear script. The script is cleared and saved immediately.

Example label script for an address, assuming its properties are named street and house_number:

return self.properties.street .. " " .. self.properties.house_number
No test run

There is no way to try a script on an entity in the editor. Test it by creating or editing an entity of the type.

When Scripts Take Effect​

  • The key is computed again with every commit of an entity. If a value used in the key changes, the entity gets a new key; the old key keeps pointing to the earlier commit.
  • A changed script creates a commit of the entity type. New entities use it at once; existing entities use the script of the type commit they are bound to (see Model Changes and Existing Data).

Virtual Properties​

A virtual property is computed by a script instead of being entered, for example a full address line from street, postcode and city. Add it on the tab Virtual Properties of the entity type with Link existing, like a normal property. The relationship properties are:

FieldNotes
position, name, label, descriptionAs for normal properties.
scriptRequired. Lua script that returns the value.
dynamicWhether the value is computed dynamically.

Virtual properties are read-only everywhere. They are computed when the entity is saved — if a related entity changes later, the value is not updated until the entity itself is saved again.