umangenius-logo
U Man Genius docs
Scripting tips & tricks

icon picker
Undocumented functions in Ninox

JT
Jacques TUR
Some functions are not included in Ninox's official documentation. These were discovered by examining the code and understanding their behavior.

TypeOf

The typeof function returns the type of a specified field.
Example:
typeof(first(select Customer).'First Name');

Eval

The eval function executes the script passed as a parameter within the context of a specified record. It returns either the value or a text indicating an error in the script.
Example:
eval("---{this.'First Name'} {this.'Last Name'}---", first(select Customer));
Output:
Sofia Young

DebugValueInfo

The debugValueInfo function returns a text indicating the type and value of the parameter passed. This is particularly useful for testing pieces of code in the Ninox console.
Example:
debugValueInfo(eval("---{this.'First Name'} {this.'Last Name'}---", first(select Customer)));
Output:any("Sofia Young")

Debug

The debug function is equivalent to console.log in JavaScript. It sends the value passed as a parameter to the browser's developer console. This is helpful for debugging code in formulas.
Example:
(select Customer where 'First Name' like "a").(
var 'firstName' := this.'First Name';
var lastName := this.'Last Name';
debug("Debug info: " + 'firstName' + " " + lastName);
)
The result appears in the browser's developer console (accessible via developer tools).

Records

The records function returns records based on a specified array of numbers.
about
Note: The array must be hardcoded; it cannot be a variable, which makes this function less flexible. It is primarily useful when you need to retrieve the same records consistently.
Example:
records(Customer, [1, 3, 6]).'First Name';
This retrieves the first names of records with the IDs 1, 3, and 6.

nx-file

The http() function in Ninox makes it possible to retrieve data from a remote server. It returns a JSON object composed of two keys: error and/or result. The result key contains the content returned by the server.
If that content is in a text format (such as HTML, JavaScript, JSON, or other text files), everything works fine. However, if it’s a binary file (e.g., an image, PDF, Word document, etc.) or partially binary, Ninox tries to store this content in a textvariable. This causes a problem because certain binary values are escaped (for example, value 92, or 0x5C in hexadecimal, which corresponds to the “\” escape character).
This is due to Ninox not being able to handle byte arrays directly. To work around this issue, we can use Base64, which converts binary data into text form. You can find more information on Base64 here: ​
Ninox provides some functions for manipulating Base64-encoded data, such as loadFileAsBase64() or loadFileAsBase64URL(). These allow you to retrieve a file (stored in a record) in Base64 format.
Back to our scenario: we need to read a remote binary file and store it in a Ninox record. In the http() function, you can define header options. Typically, you just need to specify the format you want to read using the content-type key. However, to handle binary data, we need to add another, undocumented key called nx-file, assigning it the value "base64url".
By adding the nx-file key, Ninox changes the way it processes the content returned by the server. Normally, Ninox returns the content “as is.” With nx-file, Ninox converts the response into Base64URL. Thus, instead of receiving something like:
json
Copier
{"result":"�PNG\r\n\u001a\n\u0000\rIHDR\u0000\u0002�\u0000\u0002\u001f\b\u0006\u0000����\u0000\u0001DiCCPicc\u0000\u0018�c``<���[�$����WR\u0014��\u0010\u0011..."}

… you get:
json
Copier
{"result":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqoAAAIfCAYAAAC4gv6sAAABRGlDQ1BpY2MAABiVY2BgPJGTnFvMJMDAkJtXUhTk7qQQERmlwP6IgZlBhIGTgY9BNjG5uM..."}

This new format (Base64URL) is directly compatible with the importFile() function in Ninox, which interprets it as a local Base64 URL and saves it to the specified record.
Keep in mind that most remote servers only accept requests from other servers (not from a client). That’s why it’s important to execute the http() function in a do as server context.
Below is a sample global Ninox function that lets you read binary data (images, PDFs, Word documents, Excel files, etc.) as Base64URL:
function loadFileOnBase64FromUrl(URL : text) do
var fileName := extractx(URL, "\/([^\/?#]+)[^\/]*$", "$1");
{
fileName: fileName,
content: do as server
http("get", URL, {
'content-type': "application/octet-stream",
'nx-file': "base64url"
}, null).result
end
}
end;

And here’s an example of how to use this function:
var base64UrlFile := loadFileOnBase64FromUrl(url);
importFile(this, text(base64UrlFile.content), text(base64UrlFile.fileName));

By doing this, you can retrieve a remote binary file, convert it to Base64URL, and import it directly into a Ninox record.
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.