VOLUME XC             07/20/2021

Why You Should Use Global Functions

By Michael Sidenstick, Programmer/Developer

An underutilized but very important functionality built into Ninox is the ability to define functions that will work anywhere in a database. If your database has multiple fields with similar or the exact same chunks of code present, global functions give you the ability to save time, coding and resources by bringing all of the similar code to one spot. To create a global function, just open a database and use the red wrench in the top right corner to enable administrative mode. Then, click the options tab at the top of the page, and click “Global script definitions” to open the area for global functions. If you don’t know what a global function is, the “Global Functions and Variables” video on the Nioxus YouTube Channel is very helpful for understanding how to make these functions. Instead of discussing how to create these functions, I want to talk about why they can be useful and the programming concepts behind functions.

Functions are very useful when used correctly in large codebases– in nearly every programming language, functions are crucial in developing reusable code quickly and effectively. If we had a 1,000-line program, we could break the huge chunk of code into many functions that each tackled a single task, which would reduce the number of total lines and organize the code. In Ninox, if we wanted to create four formulas that would pull from four tables, in many cases, we could write a single global function that would perform this task for each of those four cases. Then we could call the global function with the dynamic data, and not have to copy and paste any code or rewrite anything.

 Furthermore, if we had an error with a part of our code, and the code was copied and pasted in multiple places, it could be difficult to find all of the errors. When a global function is used, there is one central place where the error would originate, so you would only have to change the code in the global function itself. Furthermore, when there is an error with a part of a task, if the different tasks are sorted into functions, finding where an error takes place is much easier when the tasks are separated into functions instead of in one large block of code. If you have a codebase with hundreds of lines of code or multiple functions that accomplish the same (or similar) task(s), using global functions to organize your code requires only a small investment of time, but provides a huge return on investment in the form of ease of use in the future. Global functions are well worth the effort… give them a try.

Office 365 Integration and Team Collaboration Coming Soon to DocumentsPLUS!

Learning Lab

Join us this Thursday at 12:00pm ET or 6:00pm CET as we explore the benefits, pros, cons and differences between the Ninox App and the Ninox Cloud Edition.

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!

Sharing Feels Good!

By David Gyenes, Director of IT

Ninox introduced a few new code functions. They are not new features, but the features can be executed by code now. This makes everything more useable. These new functions are about sharing. Yes, they care about us, so they give us the ability to share. So many people have the need to share files or share views and It used to be a pain in the neck, but now we have the power to share and revoke sharing. Let’s start with sharing files. What does the syntax look like?

shareFile(this, “My File Name.jpg”)

unshareFile(this, “My File Name.jpg”)

So, this function takes two parameters. The first parameter, as many of you probably know, is the “this” and it refers to the current record. We could replace “this” with record(‘Table Name’, record Id). The second parameter is a text value which is the name of the file. Yes, we need to know the file name. But what is the output? The output is a URL we get that we can send to someone by placing it into their browser. If we try to execute the old manual way by clicking the image option in the record and selecting share, we will see that the image is shared, and we see the same link. The unsharing function works the same way. Same syntax but it revokes the share. The other sharing is sharing a table view. This also has a familiar syntax. Let’s take a look at the options:

shareView(“Table Name”)
shareView(“Table Name”, “View Name”)
shareView(“Table Name”, {“contentType: “option”})
shareView(“Table Name”, “View Name”, {“contentType: “option”})
unshareView(“Table Name”)
unshareView(“Table Name”, “View Name”)

As you can see this function can take up to three parameters, but the second and third parameters are optional and can be used together or without the other. The first parameter is always the table name defined as text. If we use the “view” parameter that goes to the second place, this is also defined as text. The third parameter would be the option or technically the format we want to share it in. This can be PDF, HTML, CSV or JSON, in syntax written all lower case. Once a Ninox view has been shared, there may come a time when that share may need to be revoked or closed down. To “un-share” a view, simply use the unshareView() or unshareAllViews() discussed earlier when you want to restrict a view to authorized and licensed Ninox users.

So go out and share this information with everyone because, after all, sharing is caring!

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.