Create your own functions
Create your own functions with Ninox to automate workflows according to your needs
Advantages
- write a script once and use it throughout the database
- concise scripts because you only need your own function and don't have to insert the entire script once or even multiple times
To define a function, use function
followed by whatever name you choose. Then, in parentheses, specify which parameters are to be used. These are separated by commas.
Define parameters respectively as follows
parameterName : parameterType
To create a function without parameters, insert empty parentheses ()
.
Like scripts, the last line in the definition of the function is the return value.
Define functions globally
To use your functions across the entire database, enter the function in the tab bar of the database under Options in Global functions.
Options are displayed when you're in edit mode.
How it works
- Enable edit mode.
- Click the Options tab.
- Enter your function(s) under Global functions.
Under Global functions you can enter your own functions
Insert the function in a Formula field of a table and that function is only available in that Formula field. This is useful when keeping repetitive sections short, or when your function refers to the current table, respectively.
Hello Mom. You are 100 years old!
Let's create a function hello
to greet a person and tell them their age. First, pass the function a string for the name and a number for the age as parameters. These parameters are inserted into a given sentence at the appropriate positions.
Example
function hello(name : text,age : number) do
"Hello " + name + ". You are " + age + " years old!"
end
Result: Hello Mom. You are 100 years old!
If you called the function like this: hello("Mom", 100)
Parameter name | Parameter type |
---|---|
name |
text |
age |
number |
Unfortunately, not all data types are currently supported by user-defined functions.
Data types for creating user-defined functions
These following data types are already available for creating user-defined functions.
Data type | Description | Example |
---|---|---|
text |
corresponds to the data type string and stands for simple text |
"Mom" |
number |
is a number | 100 |
boolean |
is either true or false | "Mom" = "Mom" "Mom" = "Dad" |
date |
is a date | date(1922, 1, 13) |
time |
is a time | time() |
datetime |
corresponds to the data type timestamp and stands for a timestamp |
datetime(date(1922, 1, 13), time()) |
Table name | corresponds to a record from the specified table | myRecord : 'Table 1' |