Back in April 2015 I wrote an article about reading server settings with C/AL code. Unfortunately, that code didn’t work in NAV 2015 and above. However, the question pops up now and then, and I decided to give it another try. Being curious myself, of course…
And I found a solution that works on NAV 2016. Didn’t test it with NAV 2015, but I’m sure one of you will.
A Codeunit that demonstrates the solution is available on Github.
The solutions is using two dll’s from Dynamic NAV:
You only need to copy those dll’s from the NAV server folder to the add-in folder on the development server in order to compile the object. No need to do that on any production server, at runtime the dll’s will automatically be picked from the NAV server folder.
Here is a screenshot of the code. Didn’t pay a lot of attention to make it very fancy. It does the trick, and it’s up to you how to implement it. Don’t forget to add some error handling as well.
The code works in both single en multi-tenant environments. In single tenant environments the database settings from the server settings and the tenant settings will just be the same.
Take a look in the server config file for the list of setting names that are available.
This example uses undocumented features of Dynamics NAV. It is not guaranteed that it will work in the future. Be very careful with using those dll’s, using them incorrectly can cause unexpected disconnects of clients. Use at your own risk, no warranties.