VOLUME XCIII             08/10/2021

Working With Files in the Ninox API: Part 2

By Adam Davidson, Director of Product Development

This week we will look at how we can read out files from the file API and display their file names in a formula field in Ninox. It is possible to get the list of files for a record from a Ninox script with the files(record) function. However this will only be possible if you are in the same database as the file record whose file you would like to read. To get files from anywhere, you will need to use the API.

		let getFiles = () => {
			let headers = {'Authorization': 'Bearer ' + '" + apiKey() + "'};
			let url = 'https://api.ninox.com/v1/teams/" + teamId() + "/databases/" + databaseId() + "/tables/" + tableId(this) + "/records/" + Id + "/files';
			fetch(url, {headers: headers}).then(response => response.json())
  			.then(files => {
				let container = document.getElementById('files_conatiner');
				let html = '';
				for (let file of files) {
					html += '<div>' + file.name + '</div>'
				container.innerHTML = html;
	<style onload='getFiles()'></style>
	<div id='files_conatiner' onclick='getFiles()'>hello</div>


This script will display the files that are attached to a record in a formula field. The fetch() javascript function is used to send a GET request (which is the default method) to the api files endpoint. The function getFiles() is executed as soon as the html is rendered on the page by calling the function in the onload event trigger of an empty style element. Files that are being retrieved from other databases can be accessed by simply modifying the url that the request is sent to and the API key if necessary.
Next time we will take a look at how to download files to a user’s device using the API.

Office 365 Integration and Team Collaboration Coming Soon to DocumentsPLUS!

Learning Lab

Be sure to attend our learning lab this Thursday at 12:00pm ET or 6:00pm CET where we’ll be hosting another open Q&A! Be sure to ask a bunch of questions so you can earn Gold Stars!

Check Out Our Templates

Did you know that Nioxus has built over 130 templates which are available to all Standard, Deluxe and Premier Nioxus members?

Nioxus University YouTube Channel

Nioxus has created nearly 100 videos and over 200 hours of content teaching you how to use and optimize Ninox, as well as our supplementary products, CalendarPLUS, ReportsPLUS and DocumentsPLUS!

Dynamic Choice Field

David Gyenes, Director of IT

One of my favorite topics is Dynamic choice fields. These are really great features to display value based on different conditions. How do we do that? Let’s dig in…
So normally we use the choice field to display records from another table. So we create a Dynamic Choice Field (DCF) or a Dynamic Multi Choice Field (DMCF). Then we define the Dynamic Value selecting a Table (ex: select Clients). Then we select the field we would like to display in the selection. This is the simple set up. But this is not all we can do.
On the table where we create the DCF/DMCF we can have some fields that acts as condition for the records being displayed in the DCF/DMCF. A simple example, let’s say or DCF displays our clients. On the clients table we have a field to determine gender. If I want to display only women in the DCF, I can set up a field next to it. This field will be a Yes/No switch. If it’s turned on, then I want to see only women, otherwise I want to see all clients. Into the Dynamic Value property I can write this code:
					if ‘Yes / No’ then
	(select Clients)[Sex = 1]
	select Clients
This way I would get different values in the field. Or I could have a different order for my results:
if ‘Yes / No’ then
	select Clients order by ‘Last Name’
	select Clients order by ‘First Name’

With a little trick actually we can change the value being displayed in the DCF/DMCF as well. We can set a switch (Yes/No field – can be hidden) on the Clients table as well. When we flip the Yes/No switch on our main table that would set all record value as well to the same. Now we can build the condition what field to display. In the Dynamic Value Name we can write a code. As example we will display First name if it’s on else display the last name:

					if ‘Yes / No’ then 
	‘First Name’ 
	‘Last Name’

So now we know how to filter records, organize them by different order or show different values. Of course, we can combine these 3 example codes above.
Setting values for DCF/DMCF:

Now we are able to set values by code as well to these fields. For DMCF we can either use the
‘Multiple choice (dynamic)’ := select Clients
(this would select all) or we can use filters on this as well
‘Multiple choice (dynamic)’ := select Clients[‘Yes / No’ = 1]
Also we can just simply assign an array of IDs to it
‘Multiple choice (dynamic)’ := [1,2,3]
For DCF it would be easier by just assigning a simple record
‘Choice (dynamic)’ := first(select Client)
Or assigning a number value
‘Choice (dynamic)’ := 1
With these features you can make your database very versatile.

Copyright 2021 © All Rights Reserved.

All logos, trademarks and names are the protected property of Nioxus Corporation or their respective owners.

“Ninox,” “Ninox Database” and the blue Ninox owl eye logo are the property of Ninox Berlin and are used with permission.