This blog post is intended to explain step-by-step how to publish Dynamics NAV Code on GitHub using the GitHub for Visual Studio plugin which you should install before continueing to read this post.
Step one is to create a new repository. We’ll do that from Visual Studio using the plugin.
As you can see in the screenshot I am connected to my GitHub account.
Here I select Create and populate the window like this:
And this creates a new Repository on my GitHub Account
Adding NAV Objects to Git Repository
Next job is to add some NAV code.
For this project I want to have four folders since the workshop has four exercises. I want to develop the exercises indepentantly even though they are build on top of each other.
In this project I don’t care about standard Microsoft objects. I don’t want to make this more complex than it already is. I am not a big fan of building code repositories that start on CRONUS objects. I’d rather do deltas in that case. Let’s keep it simple and put the text files on GitHub that people have to import in their NAV2016 database.
I simply create four folders in my explorer where Visual Studio has put my project and put all the files there I want to be on GitHub. I have created a file per object using Soren Klemmensens vbs script, no need for PowerShell.
Commit Changes
If I now go to my Changes windows in Visual Studio you can see it found 150 new files.
Smart tool! Now we select Add-All and put something in the Commit window and see what happens.
On GitHub, nothing happens. That is the funny thing about distributed version control. I can commit changes, and revert changes on my local machine without my co-workers see what I do.
I can see the commit hash and the infamous train tracks start to appear:
Sync to GitHub
All I have to do now, is to Sync to GitHub and my changes will be there, for everyone to download and change.
The challenge I have is the following: I want to share code examples from Dynamics NAV in a structured & dynamic way. They are subject to change and improvement. I want people to able to download them, report bugs and if possible fix the issues themselves.
Visual Studio Team Services
About 18 months ago I blogged about the availabilty of Visual Studio Online, or VSO.
This has since a few weeks been renamed to Visual Studio Team Services. Makes a lot of sense, since it is TFS in the cloud. Visual Studio Code is something else.
We are wondering off. I’ve been using VSTS for almost every project since it was released. It is easy to get started and allows you to combine strong agile project management tools with version control. Once you get the hang of it, it is very easy to use with Dynamics NAV.
Secure
Visual Studio Team Services is secure. When I do a customer project it allows me to assign who has access to the code and to the work items. Perfect for a project
Open Source
In this specific case, I want the opposite. I want everyone to access my code, download and improve it. Hence I was thinking of GIT.
Back then I decided against GIT, exactly because of the reason it was open source and Microsoft brought us Visual Studio Online.
Visual Studio & GIT
Since quite a while Visual Studio allows you to use GIT instead of TFVC. Hence I figured I should use that.
WRONG!
Git vs. GitHub
Now we are getting to the point of this blog. The explanation of Git vs. GitHub and what Visual Studio Team Services are using.
For almost all Dynamics NAV partners Git is new, so I expect it might be benefitial for our ecosystem to explain this.
Visual Studio Team Services & Git
If you don’t change its default behaviour and select Git as version management system your code does not end up on GitHub. This is (honestly) what I expected. But it does not work like that.
Visual Studio Team Services has its own Git server, which runs independantly from GitHub. It is hosted by Microsoft.
For me this meant I was back to square one, because I wanted to share my code on GitHub. I spent the better part of two hours figuring this out.
GitHub & Dynamics NAV
So how do I get my code from NAV on GitHub then? I’ve found two ways. One is a shortcut and one is more official.
Convert from TFVC to GitHub
GitHub allows you to import a project from TFS, including Visual Studio Team Services. I used this to convert two existing projects you can find on my GitHub account.
If you like working with Visual Studio you can use the GitHub plugin. This is explained in this YouTube video.
This allows you to work with GitHub just like you work with TFS as explained in the videos by Soren Klemmensen. Well, not 100% but kind of similar.
I’ve added a new playlist to my YouTube channel where I plan to do more videos on how to get started with GitHub and Dynamics NAV
Hardcore Git Commands
Off course you can also do hardcore GIT commands, but I am a visual guy. I don’t like PowerShell and I don’t like the GIT Commandline tools. I want to have a GUI. Git Commands are out of scope.
Visual Studio Team Services & GitHub
So, I have my NAV code on GitHub, but now I lost the possibilities of my Agile Project Management tools. Question of the day: Can I combine both?
Yes.
For what I have found out you can actually have a Visual Studio Team Services project connect to GitHub. However I have yet to start playing with it.
When CU2 was released, I totaly forgot to test something I should have.
Based on my “what the BEEP” post my friends at Microsoft decided that it was time to “clean up” and gave me a heads up.
If you type “BE” in NAV2016CU2 the keyword you get is BEGIN, not BEEP.
THANK YOU TEAM!
From what I have been told the obsolete commands are hardcoded. If you find anything that should be removed, just reply to this blog. Microsoft folks read it :). (Trust me I know).
As far as I could test I could not find the BEEP in the Symbol menu either, but I might have looked in the wrong place.
As you might have noticed in my blog post from a couple of days ago I am making an attempt to print an existing PDF from NAV.
This is a common request. For example: print assembly instructions together with a sales packaging document. The assembly instructions are an existing PDF document and the sales document is generated by NAV.
In the classic client I used a command prompt tool for this, but I figured this would be possible using a DotNET component in newer versions such as NAV 2016.
Finding a tool
Step one is to find a tool that lets you do this. I searched in NUGET packages to see if something existed. I decided to try one I found, Spire.PDF. I guess there are more tools, maybe better ones. If you have a better one, please tell me.
Installing
Step two is to install the DLL. This is explained in the previous blog.
Writing the C/AL
Last part is to write the C/AL DotNET code that prints the PDF. This starts by finding the constructor.
The easiest way is to find some C# code to copy. This is what I found on StackOverflow.
Microsoft is trying to make our life easier from an upgrade perspective with merge commandlets and upgrade codeunits. This is nice but sometimes you run into situations that are not fixable with tools like these.
I am currently upgrading one of my older customers from NAV2009R2 classic to NAV2016. Some code goes back to 3.60 and reports to 2.x.
During this upgrade I run into a number of issues that are disruptive to merge commandlets, even if I were using pages, even if I were using extensions and eventing.
Refactoring
This has everyting to do with Microsoft refactoring. There are three major application areas they have refactored that blow up my upgrade.
Dimensions
SMTP Email
Excel Buffer
This post is about SMTP Email. Dimensions we all know, I don’t think I have to write more of that.
The Shortcut
To “fix” sending emails with SMTP there is a shortcut and a “new way”.
Let me show the shortcut first.
In NAV2016 the function AddAttachment has one extra parameter
Simple fix. But if you want SMTP in NAV2016 you really should use something else.
Arguments Table | 9500 Email Item
As I mentioned in my post, Microsoft is starting to use a table as a class grouping arguments in a table to pass into a function. This is called “argument tables” and described in my blog and Master Class.
The example is a new table Email Item (9500) that helps you with sending emails.
Idea is to populate the fields of the table and then use the Send method.
There are advantages of using this, for example, you can enable editing the email in outlook. This is optiona.
It also has some flaws.
Defaults
One downside of working with argument tables is that you need a line of C/AL code per argument to populate.
With SMTP email you often have default sender and reply addresses such as the company name and a noreply@ address.
AppendBody
The Arguments table allows you to add a body. This is a long text. It is often usefull to populate the body line-by-line. Especially if you do HTML formatting.
Please note that I also use a very old version of notifications. This was discontinued somewhere after Navision 4.0. I have to upgrade this to the new Notification. Another thing that broke my “Easy Upgrade” since it was bringing in objects with name conflicts.
Naming Issue
There is a small naming issue. “Send to” should have been “Send To”. Must have slipped code review.
Attachments
The Arguments table also does not support multiple attachements.
HTML Formatted
If you want to send your email in HTML format, you cannot open it in the UI. This is the (TRUE) parameter of the Send method.
Remember my dear students in the Master Class! UI Separation. 😉
“NuGet is the package manager for the Microsoft development platform including .NET. The NuGet client tools provide the ability to produce and consume packages. The NuGet Gallery is the central package repository used by all package authors and consumers.”
So Microsoft Dynamics NAV with C/AL is part of the Microsoft Development Platform. (Ugh Ugh Ugh). So how do we use it.
Arend Jan Explains:
Visual Studio
In VS we have to create an empty project. Just create a C# Console project.
Open the package manager console View -> Other Windows -> Package Manager Console
In the window we get now we copy and paste the text from the NUGET page. In my case I want to use a PDF package to see if I can print PDF from NAV. (You can guess my next blogpost).
This is what we should have in the window after executing the command:
So we can go to our project folder and get the DLL, and place it in the Dynamics NAV Add-In folder.
NAV 2016 Cumulative Update 2 is released. I have to admit, normally I don’t pay that much attention to updates, but the last ones are on my radar because of some promisses.
Symbol Menu
Nobody could be happier with the new code editor than me. It makes me more productive and makes our environment sexier and more attractive to young people.
However, the very first piece of feedback I gave was that in some cases the Symbol Menu was not bad.
This feedback was first ignored during the Technical Preview process, but due to pressure after release it is now back.
Glad I was not the only one.
Events & Extensions
There are a couple of interesting KB articles in CU2. Mainly about Extensions and Events.
376710
You cannot publish an extension if it contains too many objects.
So somebody is trying to wrap their entire vertical solution in an Extension? 😉
376969
An extension object cannot be added when a deleted base object had the same ID.
This is a strange one. First and foremost, if you package an extension ALWAYS use ID’s in you CfMD range. I don’t recommend packaging custom objects as Extension.
You can change the automatically generated ID in the Database-Alter menu on the Advanced Tab.
I admit, it does not work too well with distributed development where each developer has their own database.
Hopefully in the (near) future Microsoft will make the required changes in NAV to make proffesional development easier out of the books so we can safely say distributed development is easy. I would also like to see GIT support.
With the release of NAV2016, more new features have been added than ever before. This raises a challenge that we have not had in a while. Translations.
Microsoft is trying to make our life easier from an upgrade perspective with merge commandlets and upgrade codeunits. This is nice but sometimes you run into situations that are not fixable with tools like these. Continue reading “Excel Buffer & Ease of Upgrade”