Publish Dynamics NAV code to GitHub

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.

You should also have your own account on GitHub.

Create new Repository

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.

GitHub1

Here I select Create and populate the window like this:

GitHub2

And this creates a new Repository on my GitHub Account

GitHub3

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.

GitHub4I 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.

GitHub5

Smart tool! Now we select Add-All and put something in the Commit window and see what happens.

GitHub6

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:

GitHub7

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.

https://github.com/markbrummel/Master-Class-Examples/tree/master/Exercise%201

GitHub8

You can download them here:

https://github.com/markbrummel/Master-Class-Examples

 

Git & GitHub vs. TFVC & VS Team Services

Let me start this post with an explanation.

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.

I’ve been experimenting with GIT a couple of years ago and have an account. https://github.com/markbrummel.

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.

https://github.com/markbrummel/NAVTEST

https://github.com/markbrummel/table-as-a-class-dynamics-nav

GitHub plugin for Visual Studio

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.

Here are some links:

https://social.msdn.microsoft.com/Forums/en-US/030a436e-9671-416f-9c98-e198ae58c415/question-about-github-and-vso-integration?forum=TFService

https://zapier.com/zapbook/github/visual-studio-online/

My Projects

Next blogs are about getting your code in GitHub. This is what I’ve done for the code examples from my books and workshops.

Depending on the amount of time I have and the requests I intend to keep experimenting with getting GitHub to work with Visual Studio Team Services.

More Sources

http://stackoverflow.com/questions/11816424/understanding-the-basics-of-git-and-github#11820206

 

NAV2016CU2 | Obsolete Commands Cleaned Up!

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!

NAV2016CU2 Intellisense

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.

Print Existing PDF in Dynamics NAV using DotNET

EDIT: Read about downloading NuGet packages here.

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.

PdfDocument pdfdocument = new PdfDocument(); 
pdfdocument.LoadFromFile(pdfPathAndFileName); 
pdfdocument.PrinterName = "My Printer"; 
pdfdocument.PrintDocument.PrinterSettings.Copies = 2; 
pdfdocument.PrintDocument.Print(); 
pdfdocument.Dispose();

PDFDocument is the constructor, so I need that as my DotNET variable.

PrintPDFConstructor

After this, I can almost copy and past the C# code to Dynamics NAV

OnRun()

PDFDocument := PDFDocument.PdfDocument;

PDFDocument.LoadFromFile('E:\untitled.pdf');

PDFDocument.PrinterName := 'HP LaserJet CP 1025nw';

PDFDocument.PrintDocument.PrinterSettings.Copies := 2;

PDFDocument.PrintDocument.Print;

PDFDocument.Dispose;

The only things I changed was the filename, printername. I replaced = with := and removed the parenthesis.

This works like a charm.

Next challenge is to write some code that combines multiple PDF documents into one big PDF, but that’s another blog for another day.

SMTP Email & Ease of Upgrade

This blog post is tightly connected to one of my previous posts:

Ease of Upgrade

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.

Attachement2009

In NAV2016 the function AddAttachment has one extra parameter

Attachement2016

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.

Using Argument Tables | Introducing Overloading in Dynamics NAV

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.

The Result

The result looks something like this

EmailItem.SetDefaults;
EmailItem.Subject := NotTxt.Subject + "Invoice No.";
EmailItem."Send to" := "Email Address";
NotTxtLn.SETRANGE("Text Code", NotTxt.Code);
NotTxtLn.SETRANGE("Text No.", NotTxt."Text No.");
IF NotTxtLn.FINDSET THEN 
  REPEAT
    EmailItem.AppendBodyText(NotTxtLn.Text);
  UNTIL NotTxtLn.NEXT = 0;

EmailItem.Send(TRUE);

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. 😉

 

Installing NUGET Packages for Dynamics NAV

One thing Arend Jan inspired me with at NAVTechDays is to start using NUGET packages in Dynamics NAV.

What the *** is a NUGET package

From https://www.nuget.org/:

“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

Packagemanagerconsole

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).

Nuget Install Package

This is what we should have in the window after executing the command:

PackageManagerConsoleResult

So we can go to our project folder and get the DLL, and place it in the Dynamics NAV Add-In folder.

AddInsFolder

And Voila

PDFPrintFromNAV

Now let me see if I can get this thing to work…

NAV2016CU2 | Symbol Menu & More

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.

NAV2016SymbolMenu

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.

StartID UidOffset

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.