Having a big mouth is easy. Everyone can go on social media and tell whats wrong in the world. But did you actually try to change it? Or are you just talking about it?
Dynamics NAV is full of legacy code and even for senior developers who have been using it for a long time it’s hard to understand so every bit of cleanup and moving back to simple and easy to understand code is more than welcome.
One year ago Michael Nielsen asked me if I wanted to create a new set of reports that would replace the standard NAV reports for those in our community who use the ForNAV product. The reports had to be easy to understand and maintain, also for end users who don’t have a huge amount of experience with C/AL and our data model.
Oh, and by the way, “please start with the document reports” is what he asked.
I’ve been working with Dynamics NAV since it was called Navision Financials. I started as an end-user with no experience in C/AL and no understanding of the data model. So all I have to do is move myself back two decades. What was so easy about Navision back then that made me able to make the move to software development.
This image shows the Sales Invoice back in those days. What made it simple?
This image shows the Sales Invoice in NAV 2018 using Report Builder. I don’t think I have to explain why I think this is not a step forwards.
Let’s say the four things I mentioned earlier are the design goals. Let’s make it a little more challenging.
This image shows the result. I hope you agree that it looks clean and not terrifying to start with if you are not a developer with a university degree.
Let’ go through the design step-by-step to see if all the design goals are achieved.
Ok, this is unfair, not my achievement, but you can start the designer from every ForNAV report directly from the Windows Client. I got this for free.
Another thing I got for free. In ForNAV you ONLY need to add the record to the dataset, not the individual fields. You can grab any field, any caption and even related tables WITHOUT doing anything in C/Side.
Let’s look at the Header.
Note that the addresses are one field. No need to do any coding, ForNAV automagically generates the address for you and uses the country code to decide how to format the postcode and country
Do you also find these NAV terms annoying when you send documents to your customers? Do your customers understand what a “Bill-to Customer No.” means? Or “Payment Terms Code”? It would be so much nicer if this shows “Customer” and “Payment Terms”.
ForNAV allows you to print the caption of the NAV table and translates it if NAV has the translation. In NAV2018 that is 22 languages! For FREE!
This is a header in Dutch, and even the Payment Terms are translated if the translation table is used. All of this without writing a single line of code. ForNAV automatically detects the metadata and handles translation for you.
The detection is done using the Design Patterns in NAV. If your ISV solution applies these best practices you get this for free to!
If you ask anyone about their top three issues with RDLC, missing transheaders and transfooters is almost always mentioned. It makes you look like an idiot if you tell your customers that making that work requires you to count lines and even then it may go wrong. You spend hours coding.
With ForNAV running totals works like you expect but you get more! The “continued” caption is translated in all 22 NAV languages for free.
So you finished creating the invoice layout your customer wanted. Everything prints on the correct position. Great! Congratulations. O yeah, by the way, this is also how the credit memo & order confirmation should look, and is it possible to create a pro-forma invoice in NAV?
We’ve all been there and in classic Navision there was this great trick. Export your report to a text file, use find and replace on the correct strings and voila, you had a working copy. Alternatively one could also use a compare tool because all the control id’s, function names and sections were called the same.
With RDLC this has become a challenge so to say and how nice would it be to have this back.
ForNAV allows two ways to make sure your reports are the same.
1. Master Sections
With Master Sections you can tell your report to use the layout for a specific section from another report. The controls that have identical names will be inherited and controls that are not present (the Sales Shipment does not have all the fields the Sales Invoice has) are removed.
2. File, Save As, Done
Ok, I’ll be honest, this was Michael’s idea, not mine. Look at the name of the DataItems in our ForNAV reports. The Header tables are called, eh, well, Header and the Line, this is getting boring, are called Line.
The benefit is that you can change the Data Source from one table to another and if they are “transferfields” siblings it just works. Even easier than in classic.
Right? This is where you should be enthousiastic enough to go to http://www.fornav.com and download the designer and the report pack to have a look. Go ahead, we won’t monitor you and it’s free. All you need is a Microsoft Training License and you can try the reports in the training numbering range or as a partner just use 70.000 or something like that.
You can even see what I am currently working on as we allow you to download the beta version of unreleased work.
If you are not tired of reading and you want to know more about how we made the standard reports even better than Navision Classic, please continue
We want users to be able to change their own reports, even if they don’t have a development license.
To do that you can create your own report layout using the standard NAV options.
Note that we don’t change the Microsoft standard code so you need to choose RDLC and NAV will tell you the report is open in Report Builder. This is not true (fortunately) since we are working with ForNAV.
Inside ForNAV you can do everything, you can even write code and add variables without any aditional license.
There are four triggers where you can add code, and you can also inherit code from a master report which reduces code cloning.
The coding experience is not fantastic but we are working on that in a next version.
You want to be proud of your investments. If you spend a lof of money on Dynamics NAV you want to get that compliment of your customer that says WOW. Your order confirmation looks awesome.
We spent a lot of time debating about fonts, fontsize and where to put which data.
We use Segoe IU 8pt except for the legal conditions.
What makes the report stand out is the PDF watermark and the way we print the Company Information.
This makes the layout looks very clean.
Dynamics NAV is born in Denmark and started with VAT in mind. Sales Tax was added later on and many of the Sales Tax features use the same fields and tables as VAT.
The first thing a NAV developer in the USA learns is “Yeah I know, it’s called VAT but it is showing Sales Tax”.
This may feel like not being a first class citizen.
We created a special report for Sales Tax that has specific Sales Tax captions and functionality. This makes it so much easier for users from the USA to understand their layout and avoids unnecessary questions.
My favorite one. Try to avoid duplicate code.
Code duplication is a nightmare for maintaining code and NAV is full of it. The reason for that is very simple. The first versions of Navision had a very simple IDE. There was no “go-to definition” and all of the business logic was written in one function.
In the 1990ies Navision introduced Temporary Tables to solve that but it never really took of. Until today things like VAT calculation is copied into every table and every report that needs it.
This image illustrates code cloning. It’s taken from the Sales Invoice report in NAV 2018. The VAT buffer is populated and printed using an Integer dataitem.
Here you can see how I tried to improve the experience.
Instead of using the Integer table I directly use the VATAmountLine as a dataitem using the Temporary property that Microsoft introduced in NAV 2015.
NOTE: Because of this you cannot use our report pack in NAV 2013 or NAV 2013R2 unless you do a platform upgrade to at least NAV 2015. (I’m sorry for that)
The calculation is done in a codeunit. Let’s have a look at how this is done.
I don’t think you ever have to change this code, but just in case. Here is how I calculate the VAT.
This uses a Variant so you can call this codeunit with any table that has a Document/Line pattern with VAT fields
We don’t want printing the report to be slow, so I am checking if you call the API with a temporary table
The API is called from the Header record and we use reflection to check if there are lines and if the lines table has the fields we need. The fields are used from an arguments table that I use as a class
I move the fields I found in the lines table via the arguments table to the VAT Amount Lines table.
The real black magic happens in the arguments table.
Examples that are easier to understand are the codeunits that update the No. Printed fields and grab No. of Copies from the Customer table.
Last item on the list. We did not change any standard NAV code. You can import our objects and run them side by side with the standard NAV reports.
The first time you run a ForNAV report we will automatically launch the setup wizard
Or if you import our objects without using them we remind you next time you print a report.
The wizard will guide you through the process and at the end it will ask you to replace the reports in the Sales & Purchase report selection.
Ok, so today I had another issue in my NAV 2018 upgrade that made my blood pressure go up. I kept getting a weird error in the Sync-NAVTenant PowerShell command. I was afraid that this would be a showstopper and I had to report the issue and wait for CU1 or CUx.
As in any upgrade I had opened the NAV2017 database in a NAV2018 C/Side, deleted everything but tables and imported my merged objects. Compile with Schema Sync Later and then you should be ready to apply the schema changes.
First of all, be aware that this takes a while. It moves a lot of data around in this step. My database is 150GB and it ran for about half an hour. We have relatively good HP Lefthand SAN boxes.
This is the error that I kept getting
Sync-NAVTenant : The following SQL error was unexpected:
Incorrect syntax near 'Unit'.
At line:1 char:1
And this is the SQL Statement that gave the error. I found it in the Windows Event Log
DECLARE @StatisticsToDrop NVARCHAR(MAX);
SELECT @StatisticsToDrop = COALESCE(@StatisticsToDrop +', ', '') + '[Clean Company$G_L Entry].'+ s.name
FROM sys.stats AS s
INNER JOIN sys.stats_columns AS sc ON (s.stats_id = sc.stats_id AND sc.object_id = s.object_id)
INNER JOIN sys.all_columns AS c ON (c.column_id = sc.column_id AND c.object_id = s.object_id)
WHERE s.object_id = OBJECT_ID('Clean Company$G_L Entry')
AND (c.name = 'Business Unit Code' OR
c.name = 'Gen_ Bus_ Posting Group' OR
c.name = 'Gen_ Prod_ Posting Group' OR
c.name = 'No_ Series' OR
c.name = 'Tax Group Code' OR
c.name = 'VAT Bus_ Posting Group' OR
c.name = 'VAT Prod_ Posting Group' )
IF @@ROWCOUNT > 0 BEGIN
SET @StatisticsToDrop = CONCAT('drop statistics ', @StatisticsToDrop)
EXECUTE sp_executesql @StatisticsToDrop
The message is indicating that it was trying to delete statistics which failed. So my idea was to do that before the upgrade myself, hoping that then NAV would skip it. And it did.
The script is one that I stole from my good friend Jorg Stryk a long time ago. You can find it here but you should make a small change.
This is the modified script. I hope this may help someone else running into this issue.
set statistics io off
set nocount off
declare @id int, @name varchar(128), @statement nvarchar(1000)
declare stat_cur cursor fast_forward for
select [id], [name] from sysindexes
where (indexproperty([id], [name], N’IsStatistics’) = 1)
and (isnull(objectproperty([id], N’IsUserTable’),0) = 1)
order by object_name([id])
fetch next from stat_cur into @id, @name
while @@fetch_status = 0 begin
set @statement = ‘DROP STATISTICS [‘ + object_name(@id) + ‘].[‘ + @name + ‘]’
exec sp_executesql @statement
The ForNAV standard reports are in public preview. We have just released CTP2 and now we want to start testing them with Visual Studio Code. In order to do that we have to convert them to AL objects.
Microsoft is kind enough to provide tooling which you can find on the June update for the developers preview.
The tool is a small .exe file you can find in the same folder as your finsql.exe and called txt2al.exe. It is documented on MSDN.
The tool takes a NAV txt object but it has to be exported using the MS-DOS command prompt using a special option.
Because it is a lot to write down I’ve actually recorded a 30 minutes video and posted it on YouTube. This video shows the commands, shows the differences in beyond compare and tells you how to make the tool run, test and put it on GitHub using a folder structure that makes sense. At least in my opinion.
Here is the video
And here is the text from my Convert.Bat file
finsql.exe Command=ExportToNewSyntax, File="D:\CAL\fornav.txt", Database="Demo Database NAV (10-0)", ServerName=.\NAVDEMO, filter="ID=70000..79999", Logfile=D:\Log_ExportFile.txt
txt2al --source=D:\CAL\ --target=D:\AL\ --rename --extensionStartID 70070000
One of the quirks of working with extensions is that you cannot run an object from the object designer. This is true for V1 and V2.
With V2 you can start an object (page) after deploy but this only works once and only in the WebClient.
If you just quickly want to check our a page or codeunit in the Windows client you can write a codeunit against an object that does not exist.
An example is the TowersOfHanoi app that Microsoft ships as example. This does not have a page extension to execute itself.
Works all the time.
Want to learn more about extensions? Contact me today!
Wizard pages are working on a revival from being almost forgotten. They were first introduced as form objects in Navision 3.0 as part of CRM. I instantly fell in love and started to create them for my own add-on.
Wizard pages have a few great advantages to normal pages and let’s go over them.
We almost lost wizard pages when Microsoft introduced the Role Tailored Client. There are only a few of them in the standard Application and the ones that do exist were in a part of Navision that Microsoft could not care less about since someone in Redmond had this briljant idea of replacing NAV CRM with Dynamics CRM which resulted in the name change of our module ro RM.
Fortunately for us some large partners had quite a few wizards in their ISV solutions and Microsoft “hacked” wizards in last minute using the Navigate page type.
Then we almost lost them again with the introduction of the Web Client. Again the Navigate Page was outscoped and the “Navigate Page” was changed to a Worksheet leaving only wizards as Navigate Pages.
Are you still with me here?
Now as part of the Saasification (a word that I hate) of NAV they are back and as always Microsoft is talking about it as if they’ve invented the freaking wheel, but they are over a decade old and the design pattern has not changed. Another proof of how smart the “old” patterns of NAV are and their validity.
Enough Navision history, get on with it…
For my ForNAV App I also wanted to make a Wizard page, just to prove how easy it is to make them and to be able to write this blog. I also firmly believe that wizards have nothing to do with “Saasification” but should be a normal part of any ISV solution.
Step 1 – Copy with pride
Wizard pages are suprisingly simple. The page itself is built on the table that you want to populate with the “SourceTableTemporary” property set to yes.
This gives a few restrictions. You cannot just build a wizard page on any table since many of the normal NAV tables have code in Validation triggers that assume you are doing something for real. If this is the case, or if you have a more complicated wizard you can make a decidated table and use that for your wizard.
DO NOT ABUSE TABLES! I cannot stress this enough. I tell it in every patterns class that I teach. Never, ever abuse any table as temporary table. Even for bespoke customer scenarios just create new ones. They are free, because Microsoft won’t check the customer license. We are not writing data to SQL.
For my wizard page I’ve stared with the Email Setup Wizard page (1805). This is a two step wizard page that has the base plumbing you need and if you copy it you make your life easier than starting from scratch.
Step 2 – Clean Up
The next step is to change the SourceTable property to your table (ForNAV Setup for me) and clean up the fields you don’t need. There is a bunch of stuff you don’t need and the compiler will help you find it.
After this step you should have somthing like this:
You now have a clean wizard with two steps. The images are already there but they only show up in the Web Client.
Step 3 – Change the descriptions
You need to change the explanations in the wizard. You don’t want your wizard to say, “Hey, welcome to email setup, let’s make it work”. You rather want something like this:
Step 4 – Change the code
You need to write C/AL code, which is cool, because C/AL is a great language.
First of all, you need to read the current values so the user get’s a headstart.
And you need to comment out some code temporarily until you’ve figured out what you want to do instead
Step 4 – Add your fields
In this step you need to add your fields and you need to decide how many steps you need. In my case two steps are fine, but the standard naming of the two steps in the email wizard are specific so I decided to simply rename them to Step1 and Step2. This allows me easier to copy and paste stuff to next wizards and makes the pattern more repeatable.
In my case I have two fields I want to setup
Step 5 – Add other stuff
In case of the ForNAV App I also want to change the values in the Report Selection so the Sales Invoice changes to the ForNAV Sales Invoice. This is an optional step although it does not make a lot of sense not to do it.
To add this in the wizard I need to create a variable and put that on a step
Step 6 – Finish and Store
The last step is to store the data in the real table and execute aditional code. In my case I need to replace the reports when this option is selected.
Off course, ReplaceReportSelection is a method of the Setup table, and those of you who were in my workshop will know that (TRUE) means HideDialog.
Step 7 – Assisted Setup
Wait, you said that Step 6 is the last! True for this blog, but you can also connect your wizard to the Assited Setup for Dynamics 365. This will be another blog.
The result is a nice step-by-step wizard that allows you to easily setup the App with some guidance.
In my previous post I’ve created a Notification and I want the notification to run the wizard. I also want to run the wizard if somebody imports the fob file and runs the report from the object designer.
Lastly I want to have a default setup so I don’t want to go through the setup each time I do some playing around.
For this I’ve created an interface codeunit that I can run from everywhere. It asks me if I want to use default values or run the wizard.
This Codeunit I run from each ForNAV report and from the Notification.
So here you go! You have the wizard pattern. Enjoy! Any feedback is appreciated.