Microsoft Gold Partner Logo_edited.png
  • LinkedIn Social Icon
  • Twitter Social Icon
  • Facebook Social Icon
  • YouTube Social  Icon

Austin  |  Dallas  |  Houston  |  New Orleans  |  Nashville

Time Saving Secrets in Dynamics NAV: Code Coverage

When a process in Microsoft Dynamics NAV takes a longer time than you think it should, and using the Client Monitor didn’t give you the results you had hoped for, another good tool to use would be Code Coverage. When you are in the (development) database, you can get to Code Coverage like this:

When you click on Code Coverage, a form opens up:

To start analyzing your process, simply click the ‘Start’ button, and then run through your process the way you normally would. After you are done, return to the Code Coverage form, and click the ‘Stop’ button. You then get an overview of all the objects that NAV touched while you ran through your process, plus Form 565 ‘Code Coverage’ that will always be in the list.

After you make all the columns visible, there are six columns on the form. Of the last three columns, the Coverage Ratio is the only one that is visible by default, but as you can see in my example, just looking at the Coverage Ratio may be a little deceptive. Once you also make the columns Lines Covered and No. of Lines visible, is when you get a good grasp of what objects NAV spent the most time in.

The process I ran through with Code Coverage started, was the release of a Sales Order. Knowing that, it may be surprising to see Table 36 Sales Header in the list, with Lines Covered = 0. The reason for that is that in codeunit 414 Release Sales Document, the Status field is modified by just assigning the new value without triggering the OnValidate, and even though the MODIFY of the record is done with validation, in my client database there is no code in the OnModify trigger of table 36 Sales Header. Hence not a single line of code was touched in table 36 Sales Header.

Table 37 Sales Line had relatively a lot of lines of code touched. You can look at exactly what lines of code were touched by selecting the line for Table 37 Sales Line in the form, and then clicking the Code button.

When you click the Code button, a new form pops up, showing you every line of code in the selected object, and some extra information.

Probably the first thing you’ll notice is that certain lines of code are black, while others are red. In general the black lines of code are the ones that NAV touched, while the red lines were untouched.

The other useful information in this form, is in the last column No. of Hits. This column tells you how often every line of code was touched. So if you filter this column No. of Hits to only show lines where No. of Hits > 0, the form will only show black lines of code. Typically you want to look at the high numbers first. The highest number in my list is 134.

But as you can see, with a filter on No. of Hits > 0, that line by itself doesn’t tell us much. So we have to release that filter again to get a better understanding of where that is.

In this situation it’s in the function ZeroAmountLine, that apparently gets called a whole lot of times more than you would expect for a Sales Order with only 11 Sales Lines. Even though inefficient, this particular piece of code would most likely not slow down my process too much, since there’s no lines of code in there that would take a long time to process, like FlowFields being calculated. So if releasing my Sales Order would have been slow, I would have moved on to the next biggest number to see if anything could be improved there.

I hope this blog has helped you on how to use Code Coverage.