create | delete
To create a record in a specific table by script, specify the corresponding table name in a button after create
.
Result: A new, but empty record in the Customers table.
To fill this new record with data, first store the expression in a variable and then use the variable to access the desired fields.
Initialize the variable newCustomer
with the expression create Customer
to store the record in the variable.
Access the fields of the new record using the dot operator .
and give the new record a unique Customer number consisting of the letter C
and a UNIX timestamp.
Result: A new record in the Customers table with a unique customer number.
Delete records automatically by specifying which records to delete after delete
.
Insert the following script in a button to delete the current record.
This is useful for linking the deletion process to another action, such as triggering an email before the record is removed.
Result: The current record is deleted.
To delete several records, combine delete
with select
.
Result: All records in the Customers table with the status 4
are deleted.
The Ninox 3.11 release introduces "Creatable if" and "Deletable if"—set conditions for record creation and deletion with the formula editor
Creatable if and Deletable if are available for all apps (web app, iPhone/iPad, Mac, Android).
In Ninox 3.11, the functions isAdminMode()
, clientLang()
, and userLang()
are mainly for client-side use. When used with Creatable if and Deletable if features, they give false results because they rely on client-side data, which is not available for server-side processes.
Conditional data management
Creatable if allows for record creation only under specific conditions, for more control over when data is generated.
Deletable if blocks records from being deleted by mistake or without authorization, which safeguards data integrity.
Enhanced compliance
Admins can apply rules that restrict certain actions, such as deleting sent invoices, to ensure adherence to policies.
Increased data efficiency
Admins can manage the life cycle of records, which avoids creating unnecessary or duplicate entries. This makes data handling more efficient.
Greater control in user workflows
Users can only create or delete records under specific conditions or through designated actions, which provides tighter oversight of user activities.
Easier workflow automation
Parts of the workflow, like creating or removing records automatically when certain criteria are met, are streamlined for efficiency.
The features Creatable if and Deletable if offer a nuanced approach to managing data within the formula editor. This is in contrast with the pre-existing methods of create records and delete records, where you only select a user role from a dropdown menu.
While the latter work as a shortcut to manage creation and deletion based on user roles, Creatable if and Deletable if let you specify more precise conditions in the formula editor.
Start by creating a new database:
Go to your workspace and click the New database tile.
Select a database template:
Choose the Offers and invoices template from the list.
Access your database:
Once the database is created, open the Offers and invoices database.
Navigate to the Invoices table:
Within your database, find and click the Invoices table.
Edit fields:
Set permissions:
In the settings pop-up, click Creatable if or Deletable if (3) to define conditions.
Configure conditions:
Use the formula editor that opens to set up your conditions as per the examples provided.
In the formula editor, type userHasRole("Supervisor")
. This means only users with the Supervisor role can create records.
Click Save to close the formula editor.
Click Save in the table settings to apply changes.
To test, attempt to create a record by clicking the plus icon. If unauthorized, a message saying You are not authorized for this action will appear.
In the formula editor, type Status = 1
. This means records with the status Open can be deleted.
Click Save to close the formula editor.
Click Save in the table settings to apply changes.
To test, attempt to delete a record not marked as Open by clicking the trash icon. Upon confirmation, if unauthorized, a message saying You are not authorized for this action will appear.
Click on the gear icon erscheint, then choose Edit fields (2) to modify table settings.