Tag Archives: NAV Architecture, Patterns & Code

MiBuSo: We have Design Patterns forums now!

Let me start by thanking Luc and Alain for making this forum reality.

The Dynamics NAV ecosystem is becomming more and more aware of Design patterns and I get almost daily questions about them via mail or other channels.

These forums are meant to share knowledge and ask questions.

You can find descriptions about Design Patterns on this Wiki:

http://community.dynamics.com/nav/w/des … fault.aspx

Or on YouTube:

https://www.youtube.com/playlist?list=P … freload=10

Let’s make this happen!

Happy coding.

PS: I am moderating the forum, so please be nice. 😉

Implementation Pattern #1 | Classes, Methods and Properies

So last week in this post I promissed you to publish the implementation patterns that help you structure your application to achieve repeatable and upgradable solutions that are easy to understand and maintain.

Not a big reader? You can watch the video of this blog post!

This is the first pattern and one of the most fundamental elements to understand before proceeding with the other patterns.

We will talk about ising classes, methods and properties in C/AL, a functional language.

Classes, Methods and Properties are elements of C#, an object oriented programming language. However there are certain elements that we can take from that language and map them to Dynamics NAV and make our daily lives easier.

This week I wrote two other posts in a series about Dynamics NAV and C# that discuss the same concept from another side. If you haven’t done so I recommend reading them first.

Dynamics NAV in C# | Part 2 | Classes (Updated)

Dynamics NAV in C# | Part 2 | Classes (Continued)

And here are the two other posts about C# and Dynamics NAV:

Dynamics NAV in C# | Part 1 | The Differences

Dynamics NAV is moving to C#, get ready to follow!

Let’s talk about the Pattern

The problem we are trying to solve with this pattern is the loose connection between tables in dynamics NAV and what you can do with it in other objects such as codeunits.

If we look at an example, we have the customer table, and a function in Codeunit 365 Format Address.

2014-11-29_20-25-52

If we want to format an address in a report, as a developer I need to know that there is something like Codeunit 365, declare it as a variable and call the right function. There is nothing in Dynamics NAV that helps me find that function.

Another example, the sales header. With this I can call the post Codeunit or the Release Codeunit.

2014-11-29_20-29-07

However, when I look at the sales order page, we see again that the codeunits are called as variables.

What would this look like in C#?

Let’s compare this to object oriented programming, C# and classes.

2014-11-29_20-29-52

In C# the customer table would be a class and the fields would be properties that have a getter and a setter. The class has a method FormatAddress, and this calls out to a generic class.

Our Sales Header and Sales Invoice would also be classes. Probably in pure C# you would increase the object orientation with inheritance, but let’s leave this a simple example.

2014-11-29_20-31-08

With a Sales Header I would be able to use the Method Post and with the Sales Invoice I could call the FormatAddress again.

Let’s do this in Dynamics NAV!

So what if we do this in Dynamics NAV.

2014-11-29_20-32-25

We would create a function on the Customer Table called FormatAddress, and then on our report.

2014-11-29_20-33-17

We don’t have to know the Codeunit anymore, but browsing through the Symbol Menu, the equivalent of Intellisense in the C/AL editor, I would see that a function FormatAddress exists and I just use it from my report.

2014-11-29_20-33-54

The Table is the class, the Function is the Method and a Codeunit is a Class.

The same would work for the Sales Header.

2014-11-29_20-34-40

This would have functions release and post. And on the page I can just call the functions.

Advantages

This pattern has a number of advantages. First of all there is a clear intention of the programmer. Everything you can do with a record in the table is clearly specified on the object.

2014-11-29_20-36-10

It reduces the learning curve for new developers, since by just looking at the functions in the symbol menu we can learn what we can do with the records in the table.

We can actually use the symbol menu. Using this pattern would make creating a Codeunit as a variable on pages and reports wrong. If you see a Codeunit on one of these objects, it is an indication that this pattern is not implemented.

When working on methods, developers have less chance of overlap changing the same object. This makes merging easier when the branches come together.

And it actually allows us to do versioning of business logic. This concept will be explained in another video or blog post.

Downsides

There are some downsides too. If you create a Codeunit for each function, you get a lot of objects making managing the application less easy. Also having more than a hundred functions on a table does not exactly clarify the intention either.

2014-11-29_20-36-49

Lastly if you call a table function from a page, the Go To Definition does not work which is highly annoying.

2014-11-29_20-36-59

To avoid too many codeunits in your application, you might use the rule that if a function is less than 5 or 10 lines of code, you can write the code in the function. We’ll touch on that too when we will talk about natural language programming.

2014 Conference season is over, NAVTechDays rocks | What’s up next ?

With NAVTechDays 2014 last week, the conference season for Microsoft Dynamics NAV is officially over.

From the perspective of a presenter, NAVTechDays is just amazing. At a cinema with a screen the size of a small house and hundreds of attendees is an experience that’s next to nothing.

I’ve already wrote some articles about what I did in Antwerp. Just in case you haven’t read them yet, you can find them here, here and here. I also recorded a video.

I had to promise Arend Jan Kauffmann that my next blog post would actually contain useful information, so hopefully it did.

Why Do You Attend All These Conferences…

…and what does Microsoft pay you? That is a question a lot of people ask me. Traveling to 6 events across the globe in 10 weeks has some serious impact on your life.

First of all, let me release you from one dream; Microsoft does not pay anything.It just does not work that way. Even if you are an MVP you are on your own. And just because you are an MVP, doesn’t make you a good presenter or a good teacher either.

For me the reason to do it, is to meet a lot of people and to get a chance to evangelise a wonderful product. The only selfish act is that paying my mortgage depends on the continuous existence of the product, so I might as well help keeping it so.

So what’s next?

I am inspired to do a lot of blogging and some videos. First of all I want to continue with my C# series that I started. I have learned a lot of C# during my trips. Even last week during Vjeko’s Mere Mortals session I got some inspiration to write an article.

From a Design Patterns perspective we are getting ready to a complete package of Architectural, Design and Implementation patterns. We have a good list of patterns on the wiki and almost 30 videos.

Together with the object-oriented methodology we presented during the writing repeatable software session we have a complete package what deserves more attention. You can expect that coming.

What about Partner Ready Software?

When we started PRS in 2011, the intention was to brand a thinktank and community initiative. With the design patterns project maturing one could argue about the value of such a concept.

Truth is we don’t know yet what will happen. There are a few options that we are currently discussing that have different futures for the brand. I’ll keep you updated as things get more clear.

So now…

…back to work all of you, you already wasted enough time reading this…

🙂

The five first Design Patterns & PRS Video’s are online

Hi, my name is Mark Brummel and…

I am happy to announce that five video’s about design patterns are online now.

The first six words are how I start all the video’s. The way to make them is pretty strict.

To make it easy I’ve created a playlist on YouTube with all the video’s

These video’s are online now:

How do I Read and Understand the Posting Routines

This video explains how the general flow of data works in Microsoft Dynamics NAV and explains the difference between posting, processing and archiving. Then it explains the Test Near, Test Far, Do It, Clean Up principle and where that can be found in codeunit 80, Sales Post.

Posting Routines in Dynamics NAV

At the end of the video we look at an example posting routine written with atomic coding.

How do I Use Temporary Datasets

This is one of my favorites. This video explains how to decouple UI from table structures and how to use temporary datasets in AL code. At the end of the video we combine Queries and Temporary Datasets in a page object.

How do I Use the Transfer Custom Fields Design Pattern

This pattern is a member of the larger Hooks pattern as described by Waldo. The ideo is to establish a contract to moving fields between tables where TRANSFERFIELDS cannot be used. This pattern will make upgrading much easier.

Data Process NAV

How do I Use the Select Pattern in a Posting Routine

In Microsoft Dynamics NAV you can only send one record as a contract to a codeunit. This video describes two ways to avoid sending extra parameters using functions. One is adding extra fields to the sourcetable, the other solution is to add an attribute table, which by itsself is a Temporary Dataset

How do I Implement the Number Series Pattern

Number Series are very user friendly and easy to implement once you know the steps. This video shows that step by step. It also explains how to make Number Series cross company in a very easy way.

Have fun.

The next five will be online soon.

Design Patterns | Video Series

For the Readiness program on Microsoft Dynamics NAV 2013 R2 I am asked to make a series of 10 video’s on creating Vertical Solutions.

book

I did not need more than a split second to say yes since it matches exactly to the book I published about Application Design and my part on the Design Patterns team and Partner Ready Software.

 

Just my cup of tea.

PRS Logo

This video series will focus on best practices to create your own solutions on top of and integrated with Microsoft Dynamics NAV and are based on the design patterns and the methodology that was developed by PRS.

When writing this blog the first two videos are online and I just finised two more. Each week I will release two video’s, except for next week when we have our Design Paterns meeting in Vedbaek.

My (ambitous) plan is to write a small blog post about each video.

The first video’s are:

How do I Implement the Number Series Pattern (YouTube)

and

How do I Use the Select Pattern in a Posting Routine (YouTube)

Tip #21 – Implementing No. Series

Editors note: This tip was brought forward from my previous blog and is still as actual as it was back then. Meanwhile the Design Patterns initiative have posted a similar walkthrough on their site.

Number series is a great feature in Navision that allows you to use all kids of numbering methods easilty and also allows the application to work the same everythere,

So how do I implement Number Series in a new table. Let’s go through that step by step. For this example we will use the Item table to copy and paste from.

Step 1 – Create the table.

A table that has number series has a minimum of two fields. A primairy key field of type code length 20. But also a second field to store the number series. This is a code field as well with length 10.

Go to the object designer and create a new Table. The first field will be created manualy like this.

Please call it No. and not something else or otherwise our copy paste actions will fail.

Secondly we will open the item table in the designer as well. Find the No. Series field and copy/paste this.

Now our table looks like this.

Step 2 – Add the code

When you implement number series in your table, there are three required pieces of code. One in the OnInsert trigger, One in the OnValidate of the No. field and a new function that is always called OnAssistedit.

We will copy and paste this code from the item table like this.

When you are done with the copy/paste action your new table should look like this.

Step 3 – The variables

When you now compile your new table you will get an error message like this.

This is because we have not yet declared the nessesairy variables. We will need two of them, the Inventory Setup table and the NoSeriesManagement codeunit. We can also copy and paste this from the item table.

So our variables are like this.

Please notice that you will still receive the same error after this.

Step 4 – Code changes

In order to have the code compile we have to change it a little bit. The code we copied is reading the inventory setup in a function but that is not nessesariy in our case. We will just read it directly.

So go to the C/AL code and do a find and replace on GetInvtSetup by InvtSetup.GET like this.

Step 5 – Save the table (Twice).

Now we need to save the table, but when we try we’ll get this error.

The reason for this is simple to explain. We have created a new field (No. Series) and started using that field in code. But because the table was not saved in between, the compiler does not know that field yet. To solve this we need to save the table without compiling.

 

And then compile the table from the object designer.

Step 6 – Create your own number series.

If you look closely at the code we just created you’ll see that it uses the field Item Nos. from the inventory setup table. There is a high chance that you will want to use a number series of your own so let’s create one. We will do this in the inventory setup table as well but this can also be any other setup table in Navision.

Open the Inventory Setup table in the obect designer and copy the Item Nos. field like this

And paste it as number 50000. And rename to Test Nos.

We will also add this to the Inventory Setup Form or page

Notice that we create a new (fast) tab for our field. This is best practice.

Run the form or page and populate the number series.

Step 7 – Change the C/AL code

To use this new number series we need to go back to the code in our new table and do another find and replace action. This time replace Item Nos by Test Nos.

And save the table.

Step 8 – The User Interface

Last step in implementing the Number Series functionality is adding it to the user interface. This is done via the OnAssistedit trigger. We will demonstrate both forms and pages.

Create a new form with the form wizzard or page with the page wizzard.

Now go to the code behind the No. field by focussing on the field and press F9. You will see the four triggers, OnLookup, OnValidate, OnDrilldown and OnAssistedit like this.

Our code will go into the OnAssistedit trigger of both the form and page and is copied from form 30. The Item card.

Now when we run the page or form you’ll see that it works and how easy it was to implement.

enjoy…

/Marq

Design Patterns are part of the official Community Wiki

We are at the verge of NAVTechDays 2013 where we will do our third Partner Ready Software presentation.

Looking back on how we started and where we are today makes me proud. We talked about a wiki when we started. Today the wiki is there in a form I would have never dreamt of or hoped for.

You probably know that the Design Patterns team blogged 8 patterns on the NAV Team blog and there is a blog explaining the team and its goal.

What is the NAV Design Patterns project?

It should have been a secret until NAVTechDays but we launched a wiki on the official Dynamics Community site. Here is the link.

Patterns

Currently we have 15 more patterns almost ready to be published and plan is to move upto 40 soon.

Also we will make a big announcement of plans at NAVTechDays to move the pattern project into a bigger perspective.

For me the patterns are the core of what every NAV Developer should know to do a good job. It’s the quest I started looking for in my book.

Keep a close eye on my blog as I will post more details on our next project soon!

logo