Category Archives: Tips and Tricks

Tips and Tricks

Tip #58 | Run Extension Objects

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!

Advertisements

Why SQL Server 2016 Management Studio Understands Navision

I spend a lot of my time in SQL Server Management Studio. I rarely ever run tables anymore from Object Desingner and run most of my data conversions directly in T-SQL.

Why? Because it is so much faster, I can script things, save and restore scripts, share accross customers etc.

One of the pain points of working with SQL Server Queries has Always been the full companyname in front of the real table name. For this reason Intellisense was more or less useless for NAV databases.

This is fixed in SSMS 2016!

When you type

select * from Custom

SQL Server Management Studio will show this

sql-2016

How cool is that!

You can download SSMS 2016 for free here

 

 

Tip #56 | Fix Error : Sorting cannot be done based on the XX field(s)

Today I’ve spent some time in NAV2016 figuring out this error message:

Sorting

As you know in NAV2016 you can sort on each column even if there is no key and even if it’s a flowfield. So why am I getting this error?

In my case the Test field is a Flowfield of the type COUNT to another table. This should work fine, so why doesn’t it work here.

Reason is that the SQL Data Type is Integer instead of VarChar. A very old trick to make a SQL Database sort a Code field just like the Native database.

The SQL Data Type in the “Other” table does not match this SQL Type hence the sorting fails.

Since I could not find any info online on this message I thought it was worth sharng.

Sorting2

ALWAYS! Restart Service Tier after FOB Import!

Blogging about your own mistakes is always easiest. Reasoning is simple; if I make the mistake, chance is someone else makes it too.

Yesterday we had quite some panic at one of my large customers. After importing a fob file with some (small) changes some reports started to break that were not changed by the release.

Not all the users were suffering from this, only few, and after restarting the client, at first, the issue seems to be resolved.

However after a few hours we had the issue returning at users who had already restarted so we had some panic since it kind of goes against one of NAVs strong principles. Consistency. IF you have issues with NAV it is always relatively easy to reproduce.

Fortunately this was the case after some testing but debugging and restarting the client did not change the issue. It persisted.

What do you do in cases like this? Scream loud and wave your arms? No. Stay calm and look for differences. ;-).

After some thinking I realised that I had not restarted the service tier after importing the FOB. This “should not” be required since the new metadata is picked up automagically. However after restarting the service tier the issue was solved.

Since the issue was with a report, I emailed back and forth with Michael Nielsen who does first line support of the reporting tool we use, ForNAV. He confirmed quickly that importing a fob MAY cause inconsistency in your metadata and it is an issue that is very hard to troubleshoot or even reproduce with NAV.

So I’ve learned my lesson and will from now on always restart the service tier after importing fob files.

Tip #54 | PowerShell Merge – A clustered key can appear only once in a table

If you upgrade your database to NAV2016 using the PowerShell Merge commandlets and have a change to table 49 you will run into this issue.

Table 49 is the Invoice Posting Buffer table that NAV uses to create G/L entries for each unique combination of values in the Sales and Purchase documents. With the NAV2016 release Microsoft have added the Deferral Code field to this table and the primary key.
Continue reading

Tip #53 – Locks, Blocks, Deadlocks and Timeouts | What are they

Recently I’ve been asked to do a code review of a vertical solution. Since these are always interesting projects I cleared my schedule and planned an interview to see what it was about. I’m curious by nature.

During the interview I was told that some of their customers were complaining about deadlocks. This was going on for a while now and they did their best to look at the problem and even created a chart with deadlocks per day.

This was honestly not that much so I figured something else must be wrong. After the intake we spent some time looking at one customers system and I started up some measurements in SQL Server Profiler. Nothing fancy, just some lock events.

2015-09-15_08-06-54

This showed that not deadlocks, but locktimeouts are causing the problem. From a user perspective they almost look the same.

Here is the deadlock message:

deadlock

And the locked message:

Lock

But the source of the problem can be entirely different.

Simulate a (b)lock timeout

This is realatively easy. Simply create one codeunit that reads a customer record and hold the transaction with a confirm. (Never do this in real life kids)

Lock Code

Now simply run this codeunit twice and the timeout message will appear.

Simulate a deadlock

This is a little harder. We need two codeunits this time.

deadlock code

In this scenario we read two different customer records with a confirm in between.

Start both codeunits and then quickly press the confirm message. If you do this within the locktimeout window (default 10 seconds) you will get a deadlock.

Locktable

This last example also proves the myth about locktable busted. This is probably the most ambiguous command in C/AL language. It does not what it implies. It does NOT lock the table, but only locks the specific rows you read in the database.

Microsoft, can you please rename this to something that makes more sense?

Tools

You can also measure blocks and deadlocks using the tools Jorg Stryk provides for free. http://dynamicsuser.net/blogs/stryk/archive/2014/10/10/directions-emea-2014-troubleshooting-nav-2013-r2.aspx