Scripting tips & tricks
Here we've collected all the tips and tricks we've shared with the Ninox community in the official forum.
In this section
Ninox language basicsNinox's scripting language is used to write the formulas, buttons and triggers of your databases. This page gathers what you need to know before writing your first lines.Declaring variables: var and letBoth var and let can be used to declare a variable. Unlike in JavaScript, there is no difference in scope between let and var in Ninox.Writing your own functionsThis instruction allows the creation of a new method that can be either local (restricted to the code where it is declared) or global (by inserting it into Options/Global Functions).Choosing based on a condition: if, then, elseThe if statement can return two different values. It is important that these two values are of the same type; otherwise, the compiler will return an error:Repeating an action: for and whileA loop repeats an action: going through all of a customer's invoices to add them up, creating one line per month, checking every record of a table…Finding records: select, where, from, toThe select statement returns an array of records (nid). It can be combined with the where, from, and to clauses.Sorting results: order byThe order statement sorts an array of nid, rid, or JSON objects and returns the same array sorted. The keyword by can optionally follow order.Creating, deleting and duplicating recordsThese instructions allow you to create, delete, and duplicate a record. Their usage is straightforward and well-documented in Ninox's official documentation:Working with JSON dataTo create a JSON variable (referred to as any or sometimes complex by the compiler), declare it as follows:Working with arraysManipulating arrays of text or numbers is straightforward:Undocumented functions in NinoxSome functions are not included in Ninox's official documentation. These were discovered by examining the code and understanding their behavior. You will also find them, along with the nx-file header …Using a record's IDEach new record in Ninox is assigned a unique ID (identifier). The numbering starts at 1 for a new table and increments by 1 for each new entry (2, 3, etc.). Deleted IDs are not reassigned. Therefore, …Dynamic choice lists: Dynamic Choice and MultiChoiceDynamic Choice fields return either text or numbers corresponding to the IDs of records.Formula fields: circular referencesA formula field can read the fields of a linked record, even when that record belongs to the same table.
