Manipulating Record IDs in Ninox
Record IDs in Ninox
- Each new record in Ninox is assigned a unique ID (identifier).
- The numbering starts at
1for a new table and increments by1for each new entry (2,3, etc.). - Deleted IDs are not reassigned. Therefore, the highest ID in the table reflects the total number of records created, including those that were deleted and are no longer visible.
- ID Representation:
- IDs can be represented as numbers or text.
- When represented as text, the ID combines the table's ID (one or more uppercase letters) with the record number.
Example:"A1"
Key notes on IDs
- Converting an ID to Text:
- Use the
string()function to get a textual representation of an ID. - The
text()function only returns the numeric part of the ID as text. Example:"1".
- Use the
- Example:
string(maTable.id); // Correct textual representation, e.g., "A1"
text(maTable.id); // Only the numeric part as text, e.g., "1"
- Using IDs in Expressions:
- When performing arithmetic or concatenation, the ID adopts the type of the other data.
- Example:
var t := "Num ID: " + maTable.id;
Output : Num ID: 1
Searching for Records by ID
To retrieve a record by ID in a where clause, you can use either a number or a text representation.
Using a Number:
select Customer where id = 1;
Using Text:
When using text, ensure that the ID includes both the table's ID and the record number.
Example:
select Customer where id = "B1";
Extract the record number from an ID
This function lets you pull out the record number from a text‑based ID (e.g., A1):
function recordNumber(id : text) do
"Capture the digit group.";
number(extractx(id, "^[A-Z]+([0-9]+)$", "", "$1"))
end;
"Example: apply to the current record’s ID"
var numId := recordNumber(string(myId));
string(myId) converts the ID to text.
RegExp ^[A-Z]+([0-9]+)$ means
^[A-Z]+→ one or more letters at the start,([0-9]+)→ the digits we want (capture group 1),$→ end of the string.
extractx(..., "", "$1") returns only the captured digits.
number(...) converts that digit string to a number.
