Undocumented Ninox Functions

By Jennifer Neighbors, Senior Consultant

You may have heard rumors about “secret” or undocumented Ninox functions and wondered what all the excitement was about. Let’s look at these in detail and get the full story.

The biggest revelation here is a function named “sleep”. Sleep pauses execution of code for a defined number of milliseconds. Use the sleep function like this:

							
					sleep(3000)				
			

This line will pause execution of code for 3,000 milliseconds, or 3 seconds. In actual practice, enter the number of milliseconds that works best for you. The sleep function is especially useful if you are executing code on the server. Server-side code runs so quickly you may need to pause it so local operations (like creation of a pdf document to be used as an attachment in an email) can catch up. Depending on your needs, you may benefit by experimenting to discover just how long the pause needs to be.

Also very useful are the “Created by” and “Modified by” functions. They allow you to see who created or last modified a record without that person needing to select their name from a list of users. Ninox knows who the logged in user is and can simply insert that instead of needing a user’s input.

To create this, insert a formula field onto the form and use this as the formula:

							
					'Created by'				
			

or

							
					'Modified by'				
			

Use this for any form where the user needs to fill in information about themselves such as a timecard, for example. There’s a gotcha on using any type of user information in forms, however, that you may want to watch out for. If the user is removed from the team after the information is filled in on a formula or a user type of field, the value will disappear. This is because the source of the data – the user – is no longer a user. There are a couple of solutions for this. One I like to use is to put a line of code into the “Trigger onCreate” function of the table to automatically store the current user’s name in a noneditable text field when the record is created. This will store the creator’s name permanently regardless of whether the user is later dropped from the team. You will probaby want to make this noneditable text field invisible until it is needed.

To get a date and time stamp for when a record was created or last modified, you can use the functions “Created on” and “Modified on”. The shortcut for these functions are the better-known equivalent functions _cd and _md. When you use the underscore equivalent functions, Ninox will replace them with their longer versions, like this:

_cd will be changed to ‘Created on’

and

_md will be changed to ‘Modified on’

These two functions store both the date and the time. To get only the date oronly the time, use a formula like the ones in the following examples to pull out just the information you need:

							
					date('Created on')
time('Modified on')				
			

Now you, too, are in the know on these “secret” functions.

en_USEN