Microsoft Dynamics NAV

Team Blog

May, 2011

  • Microsoft Dynamics NAV Team Blog

    Error affecting Sales and Purchase Invoices containing Item Tracking lines


    This article handles another common issue, seen when handling documents containing Item Tracking lines in NAV 2009.

    In this instance, the problem affects Sales and Purchase Invoices and occurs when splitting the relevant shipment or receipt lines and then posting the invoice.

    Both solutions should be applied where appropriate, as the issues affect similar aspects within Sales and Purchasing.


    KB 2479028

    "Tracking Specification Entry No. [Entry_No.] Already exist" error message when you try to post a purchase invoice in Microsoft Dynamics NAV 2009

    Assume that you split a receipt line with item tracking into two invoice lines of a purchase invoice in Microsoft Dynamics NAV 2009. When you try to post the purchase invoice, you receive the following error message:

    Tracking Specification Entry No. Entry_No. Already exist


    KB 981785

    Error message when you post a sales invoice for a lot tracked item in Microsoft Dynamics NAV: "Tracking specification entry no [Number] already exists"

    After you use the Get Shipment Lines function two times to split a sales invoice into two lines for a lot tracked item in Microsoft Dynamics NAV, you post the sales invoice. However, you receive the following error message:

    Tracking specification entry no Number already exists.

  • Microsoft Dynamics NAV Team Blog

    Error when posting documents featuring Item Tracking lines


    In NAV 2009, there have been issues posting some documents containing Item Tracked lines.

    This entry brings together 3 KB articles which address these issues, with the intention that a system could be patched with all the relevant fixes at the same time.

    When encountering the following generic error, users can refer to the articles first, in order to identify if a suitable solution already exists and therefore resolve the problem in a timely manner:


    Qty. to Handle (Base) in Tracking Specification for Item No. [item no.], serial no.: Serial No., lot no.: Lot No., is currently [quantity 1]. It must be [quantity 2].


    KB 2536288 – NAV 2009 SP1

    When you try to post a transfer order line that has the defined Item Tracking for shipment in Microsoft Dynamics NAV, you receive the following error message:

    Qty. to Handle (Base) in Tracking Specification for Item No. Item No. , Serial No.: Serial No. , Lot No.: Lot No. is currently Qty.1 . It must be Qty.2 .


    KB 977259 – NAV 2009 – fixed in SP1

    Error message when you post a warehouse shipment after registering picks for a lot tracked item

    Qty. to handle (base) in tracking specification for item [item number] serial no., lot no., [lot number] is currently - [quantity 1] , it must be - [quantity 2] .;EN-US;977259


    KB 983575 – NAV 2009 SP1

    When you try to post a warehouse shipment for a lot tracked item in Microsoft Dynamics NAV 2009 SP1, you receive the following error:

    qty. to handle(base) in tracking specification for item no. Item No. , serial no.: Serial No. , lot no.: Lot No. , is currently Quantity . it must be Quantity (base);EN-US;983575

  • Microsoft Dynamics NAV Team Blog

    RDL Report Design: ReportItems! and why are fields not shown in the header when printing (works OK in preview)?




    In Headers and Footers in RDL Layout we cannot just add fields from the dataset. Instead, we must add the field to the Body of the report (but hide it), and then use the ReportItems! collection in the header to refer to the field in the Body.

    This method is used on almost every report in NAV. But some times the field is hidden too well and is not shown in the header when the report is printed.

    Further details about ReportItems! here:

    Using the ReportItems Collection References in Expressions (Reporting Services)

    Print versus preview

    The report viewer renders the data differently depending on whether it prints or previews. Preview is optimised for an on-screen user experience, and interactive features like interactive sorting, document map, hyperlinks etc are available. Print is optimised to fit the report to a piece of paper.

    The two renderings render ReportItems! in different ways. In preview we use "soft pagebreak" while in print we use "Hard pagebreak". With hard pagebreak, ReportItems! will only have a value if the field that it refers to is on the current page. While with soft pagebreak, it doesn't matter so much where in the report a field is.

    Further details about Rendering here:
    Understanding Rendering Behaviors 

    Another different behaviour has to do with how we hide the field in the body. This behaviour is not very logical, and it may change in future versions. But we found that for the current versions of RDL and report viewer, there is one small but important thing to be aware of when hiding the field in the Body:
    If you hide the whole column or the whole row where a field is, then this field will not be visible via ReportItems! in Print. It will still show in preview. To avoid this, do not hide whole table rows or columns, but make sure to hide only individual field(s).


    No need to waste paper

    Finally, to see how your report will look when printing, you don't have to actually print it out. From the preview, just select "Print layout":



    Then the preview will change its rendering to Print. Unless the report uses CurrReport.PREVIEW anywhere in C/AL code in which case the "Print Layout" button is not available.

    It's a good idea anyway when testing your reports, just to look at them in "Print Layout", since some times this does look very differently from the normal preview.



    Lars Lohndorf-Larsen

    Microsoft Dynamics UK

    Microsoft Customer Service and Support (CSS) EMEA

  • Microsoft Dynamics NAV Team Blog

    RTC over WAN – What is the Required Bandwidth for my Workload


    As you probably know we shipped Dynamics NAV 2009 R2 with a few features to support running the RoleTailored Client over WAN. Specifically we added the capability of using Certificates to validate the Server that the client is connecting to and a Login dialog that enables a NAV user to type in credentials that are different from his/hers current windows credentials. How to use and configure this is well documented and available on MSDN at this point. (

    The question that remains is what kind of bandwidth is needed when deploying RTC over WAN. As you probably also know we published some initial findings at the time of release for R2 ( These numbers were pretty generic but still valid. Our tests were done by posting 10 sales orders programmatically. We did this on connections between 300/300 Mbit and 10/1 Mbit. Let me reiterate the most important findings:

    Two factors make a difference from a network perspective:

    • Latency
    • Bandwidth

    With regard to latency the chart above shows that as we added latency between client and server our ability to utilize bandwidth decreased. This makes sense as added latency makes us wait for network I/O rather than server CPU cycles. The elbow seems to be somewhere between 75 and 125 ms latency.

    For bandwidth we saw that the upstream bandwidth from the client to the server seemed to have a significant impact on the response time. Specifically we saw that if we throttled the bandwidth below 0,1 Mbit the response time almost doubled.

    Now for the interesting part – how can you go about measuring the required bandwidth for your own workload. I will provide one example (which was also shown at Convergence Atlanta 2011 and Directions EMEA 2011).

    First let us set up Performance Monitor to capture data for us:

    • Capture Bytes Sent/sec and Bytes Received/sec for Network Interface Counter

    Make sure to capture the relevant NIC

    • Change sampling to 1 sec

    Now we are ready to run the test. For this example the test is just opening the RoleTailored client. Before you go ahead make sure that nothing else is consuming bandwidth at this point.

    • Go back into Performance Monitor and start the capture
    • Open the RoleTailored client and wait for it to fully render
    • In performance monitor stop the capture

    To view the results go back into Performance Monitor:

    • Create Report in Performance Monitor using captured file

    • Look at the numbers for Maximum for both Bytes sent and received

    To transform these numbers into something useful some basic math will have to be applied.

    The numbers in the report are bytes per second. To get to bits per second multiply the number by 8. To get to Kilobits per second divide by 1024 and finally to get to megabits per second divide by 1024 again.

    As an example if the captured number was 162.276 as above this would mean:

    Bits/sec KB/sec MB/sec
    Bytes received 162276 1298208 1267,781 1,238068

    This exercise can be applied to any operation that you would want to separate out in the RTC. If your remote users would want to post sales orders this is what you should measure. If they will be running specific reports you should go ahead and measure the required bandwidth for a single instance of that report.

    - Claus Busk Andersen

  • Microsoft Dynamics NAV Team Blog

    Use of multiple Units of Measure on non-managed Locations


    This is the first in a regular series of blog entries covering different areas of SCM functionality in NAV and is intended to make you aware of related issues, when applying solutions, as well as additional resources which are available.

    In this entry, we will discuss a common query which is reported, concerning the use of multiple units of measure on Locations which are not fully managed, but where the Bin Mandatory flag=True.

    When using a non-Directed Put-away and Pick Location which has Bin Mandatory=True, NAV does not currently support the use of multiple units of measure.

    If the user wishes to use bins with multiple units of measure, they will need to use a fully managed Location, e.g. the WHITE Location, where Directed Put-away and Pick=True.

    This issue can occur across a range of documents and results in unexpected pick and/or put-away suggestions from the system.


    The scenario has been documented and the following KB articles on Partnersource, contain further information – KB 930994 documents the functionality and KB 895075 provides an example of an issue which incorrect set-up of the Location can cause:


    KB 930994

    KB 895075


    The development team are currently looking into the possibility of adding support for multiple Units of Measure in a future release.

  • Microsoft Dynamics NAV Team Blog

    Lists of Local Regulatory Updates per Country Version


    While working for a partner some time ago (and on this project), I remember how hard it was trying to find local regulatory updates among ton of material available on PartnerSource and CustomerSource. With time, PartnerSource and CustomerSource search improved a lot, RSS was added which made it a bit easier, but this didn’t help much with catching up with local regulatory updates. We decided to simplify things a lot, by providing a single place per country and per Microsoft Dynamics NAV version to go to when looking for all/latest local regulatory updates.

    If you visit a product downloads page (e.g. NAV 2009 SP1 product download page), for supported NAV versions on PartnerSource or CustomerSource, you’ll find that the Downloads section of the product download page now contains links to Local Regulatory Update pages. The Local Regulatory Updates pages contain a list of released Local Regulatory Updates.

    When you click on the Local Regulatory Updates link (e.g. German NAV 2009 SP1) you’ll get a list of released Local Regulatory Updates for particular NAV country version.

    NOTE: Where available these pages are also translated in local languages (e.g. German NAV 2009 SP1 page translated).

    We’ll keep maintaining those pages every time we release Local Regulatory Update for local versions, so keep them in your Favorites and don’t be shy with those “likes”  on Local Regulatory Updates pages. Also let us know what you think about this.

    -Ivan Koletic

  • Microsoft Dynamics NAV Team Blog

    Microsoft Dynamics NAV Changes by Version


    Microsoft Dynamics NAV has had multiple changes to the underlying code in order to optimize performance of NAV on SQL Server. The chart below shows the changes by version.


    In order to use the REPEATABLEREAD, changes are needed after installing the latest hotfix to enable the option. The following information outlines this and should be used ONLY after testing and discussion with your SQL DBA. REPEATABLEREAD support was adding on the following hotfix version and later for NAV, it would be recommended to use the latest hotfix builds, the information below is to give a reference of when the support was added, to better understand if you are currently on a version that supports this change:

              5.0 SP1 – (Build 30482 / KB 979135)


               6.0 SP1 – (Build 30609 / KB 978100)


    1. Apply the latest hotfix for the specific version of NAV following all the guidelines/installation instructions for updating to a newer platform hotfix.
    2. Configure NAV to use the REPEATABLEREAD isolation level in Micrsoft SQL Server. You can do this by enabling the 4194304 flag in the Diagnostic field of the $ndo$dbproperty table in the NAV database. To enable the 4194304 flag, run the following TSQL statement against the NAV SQL database:

                       update [$ndo$dbproperty] set diagnostics = diagnostics | 4194304

        for more information about Microsoft SQL Server transaction isolation levels, visit the topic 'Isolation Levels in the Database Engine' on Microsoft MSDN.

    Enabling the REPEATABLE READ isolation level in NAV will improve general performance in situations where multiple users are experiencing blocking when they are entering journal entries, sales order entries, purchase order entries and similar tasks.

    The difference between the SERIALIZABLE transaction isolation level and the REPEATABLE READ transaction isolation level is that SERIALIZABLE transaction isolation level protects against phantom reads. Therefore, enabling REPEATABLE READ transaction isolation level introduces a theoretical risk of phantom reads. The following example shows what this means from a C/AL perspective.

    Note: Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

         MYTABLE.SETCURRENTKEY("Document No.", "Line No.");
         MYTABLE.SETRANGE(MYTABLE."Document No.", '1');
         MYTABLE.SETRANGE(MYTABLE."Line No.", 1, 10);
         IF MYTABLE.FIND('-') THEN
           UNTIL (MYTABLE.NEXT()=0);
         IF MYTABLE.FIND('-') THEN
           UNTIL (MYTABLE.NEXT()=0);

    With SERIALIZABLE transaction isolation level, all existing records will be locked during the first "REPEAT UNTIL" loop and other users will also be blocked from inserting new records within the specified range. The record that has Document No=2, Line No=1 will also be blocked. Therefore, the second loop will always read exactly the same result as the first loop. With REPEATABLE READ transaction isolation level, someone can theoretically insert a new record within the mentioned range which will then appear as an additional record in the second loop.

    To disable the 4194304 flag, run the following TSQL statement:

          update [$ndo$dbproperty] set diagnostics = diagnostics  ^ 4194304

    Microsoft recommends thorough testing before making any changes to a live environment to ensure that there are no unexpected results.


    Fast Forward-only (FFO) for Browse cursor with OPTION (FAST x)

    Microsoft Dynamics NAV replaced the Cursor type from DYNAMIC to Fast Forward-only (FFO) for Browse when in a Browse transaction in hotfix releases. A Dynamic cursor is still used when inside a write transaction. The OPTION (FAST x) support was added after the change to FFO for Browse to improve performance. It would be recommended to be on the latest hotfix builds to include the OPTION (FAST x) support. No additional setup is needed once the hotfix has been implemented. Again, the following information is for a reference to know if you are on a build that has the OPTION (FAST x) support, it would be recommended if you are not that you obtain the most current hotfix release for the version you are on:

              5.0 SP1 – (Build 29729 / KB 974798)

              6.0 – (Build 29894 / KB 974798)

              6.0 SP1 – (Build 29958 / KB 974798)




    Nick Haman

    North America Senior Escalation Engineer

  • Microsoft Dynamics NAV Team Blog

    Finalizing the Role Tailoring of Microsoft Dynamics NAV


    See continuation of this post here: Finalizing the Role Tailoring of Microsoft Dynamics NAV – Take II

    “Dear partner and customer, it’s up to you!” That’s a little bit provocative and not all true, of course, we would very much like your help in completing the story on how to tailor Microsoft Dynamics NAV to any role.

    We at HQ can’t complete the story alone because we don’t know exactly how features and functionality are being used in your solutions. This blog post is therefore meant as a repetition of some key concepts of role tailoring and an invitation to collaborate with you on defining remaining relevant role profiles and then to put together two configurations that we will ship as samples. See attached files.

    Role tailoring is mainly represented by the 21 out-of-the-box profiles, which each has a specific Role Center with crafted Cues, selected actions and reports, and a navigation pane representing a selection of the Microsoft Dynamics NAV functionality relevant for the user of this profile. The chart part on each Role Center adds KPI capabilities through a selection of chart definitions. The MyCustomers, MyItems, or MyVendors parts and the notification part give overview and powerful short-cut ability. Role Centers can also contain external collaboration parts, such as Outlook and Connect.

    The standard placement and visibility of fields on pages and in columns, as well as the selection of promoted actions, reflect historical choices that we made here at HQ. This out-of-the-box selection is a common denominator and represents a consensus reached when developing the functionality.

    With configuration, the game has changed! The following outlines some of the new plays that we can make.

    Deeper configuration of a profile:

    • List places/list parts and columns: Select visible columns and their sequence. For example, an order processor may need other columns than bookkeepers or warehouse workers do.
    • List places and Action Panes: Promote actions or related information that is relevant to the profile and remove those that are in the way. Remove also unused actions from the menus.
    • Promoted fields on list places and FastTabs: This requires specific knowledge. A best-guess selection was made for NAV 2009, but no changes have been made since.
    • Views on list places: Some views were defined along with the Cues, but we must define more.
    • Task pages and card pages: The Action Pane can be tailored, and menu items that are not relevant for the company can be removed to make the central functionality more visible.

    UX topics:

    • The Freeze Pane is not included in all list places out-of-the-box except in list places that are configured. (You can recognize configured list places by their Freeze Pane.)
    • Keyboard shortcuts Ctrl+Page Up and Ctrl+Page Down to browse cards are not used by some infrequent users. The mouse alternative, Previous and Next buttons, has therefore been highlighted on some cards.
    • Some list places are referenced frequently and some users wants them easily accessible. The “Open in New Window” function that is available on the right-click menu and on the Actions menu has been highlighted on master data list pages, such as Customers, so that it can be quickly accessed with Alt+Tab when working on a quote or a sales order.

    Utilize Action Panes and Activities parts to introduce concepts or ideas to inexperienced users.

    The sales order page, out-of-the-box, has Action Pane groups beginning with New and ending with Reports. By creating additional groups and organizing the menu items in a usage sequence, the functionality is surfaced in a manner that makes it easier to on-board. See the sales quote page for an alternative on how to sequence menu items in the Action Pane.

    Utilize the ability to create “activity centers” on the navigation pane.

    The return process, for both purchase and sales, has been utilized to exemplify how all relevant lists needed to complete a specific task (processing returns) are gathered in one “activity center” on the navigation pane. The role centers for the business owners have out-of-the-box similar structure of the navigation pane.

    Request for Collaboration

    Please implement and test the attached configurations and provide your feedback on the content and the effectiveness of the configurations. We would also appreciate any extra input you can offer, such as:

    • Definitions of good views, e.g. Items and Customers list places
    • Which combination of application should we modeled in a company to make powerful configurations
    • Anything else?

    Concerning the Attached Configurations

    To import a configuration, save the configuration XML file. In the RoleTailored client, click Departments, click Administration, click Application Setup, click Role Tailored Client, and then click Import Profiles.

    The configurations files for Alicia (purchasing agent) and Susan (order processor) assume that the following functionality is used at the sample company:

    • Document Approvals. Approval buttons are highlighted on sales quotes and sales orders
    • Warehousing. The company is running WMS, therefore:
      • Whse. Shipment and Posted Whse. Shipments are highlighted on Related Information menu.
      • The Bin Contents shortcut is promoted.
      • Service Management is not used (some information on FactBoxes and FastTabs have been removed)
      • Blanket orders are not used.
      • Foreign Trade, E-Commerce and Prepayment is not used by the company (removed from all configured transaction document)

    Known Limitations

    • Each place, that a list or card page can be called from, represents a new instance of a configuration, even for the same page. A new configuration needs to be done for each case.
      The limitation is valid for a view where some fields may be more interesting than others, such as when looking at released order compared to open orders, however, it was the not the intention to duplicate that principle to the Departments page. For example, the Items list page has been referenced at several departments, but each instance needs to be configured. This limitation has been partly handled in the attached configurations except for list places that are views originated from Cues.
    • We cannot configure or remove menu items from the Related Information menu.
    • We have no way to ensure a tight and consistent UI between PCs. Configuration and personalization can change from one PC to another. We do not have a “company pattern” or similar.
    • Navigation pane items generated from Cues are present on Home and cannot be moved to another activity center.

    Best regards
    Philippe Jacobsen

  • Microsoft Dynamics NAV Team Blog

    Commerce Gateway with Isolated Hosts and Biztalk 2010


    The following error may be encountered processing an XML document in the receive pipeline when using Commerce Gateway with Biztalk 2010 and Visual Studio 2010:

    There was a failure executing the receive pipeline: "Microsoft.BizTalk.DefaultPipelines.XMLReceive, Microsoft.BizTalk.DefaultPipelines, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Source: "XML disassembler" Receive Port: "Navision_to_CommerceGateway" URI: "CG://Navision_to_CommerceGateway" Reason: The document specification <Assembly Name> from assembly <Assembly Name, Version=, Culture=neutral, PublicKeyToken=Token ID> failed to load. Verify the schema for this document specification is deployed and is in the Global Assembly Cache. 

    In this scenario, Commerce Gateway Service hosts a BizTalk isolated host. The receive pipeline is executed within the context of this service. BizTalk Server 2010 by default deploys and looks for assemblies in the .Net Framework 4.0 Global Assembly Cache (GAC). The Commerce Gateway Service, however, by default runs on .NET Framework 2.0 and looks for assemblies in the .NET Framework 2.0 GAC. To work around this error, you can place the assemblies used by the receive pipeline in the .NET Framework 2.0 GAC.

    To place these assemblies in the .NET Framework 2.0 GAC, use the gacutil tool, which ships with the .NET Framework. The tool will be located under <root>\ProgramFiles\MicrosoftSDKs\Windows\v6.0\Bin\gacutil.exe. Note that there might be multiple versions of the gacutil tool on your computer. To determine that you are using the correct version (version targeting .NET 2.0 and which will install into .NET 2.0 assembly cache), Open a command prompt as an administrator, browse to this path and type gacutil.exe. If you see a version number less than 4.0,, you have the correct version of the tool.

    You can read more about how to use the tool to install assemblies into the GAC here:

  • Microsoft Dynamics NAV Team Blog

    Getting Started with an Add-in Assembly for Microsoft Dynamics NAV 2009 R2


    One of the new key features for Microsoft Dynamics NAV 2009 R2 is the interoperability extension with the .NET Framework, also called the DotNet interop feature. This feature allows the AL code to call out to .NET types and use the exposed methods and properties. The types can be system types installed with the .NET Framework, or other applications that register assemblies in the Global Assembly Cache (GAC), or it can be custom assemblies that are stored in subfolders relative to the Microsoft Dynamics NAV server or client.

    This article will in a few words explain how to get started with an assembly that will be stored in the Add-in folder and the target audience is intended to be the AL developer that has no or very little experience with programming in the .NET environment.


    The following tasks will be described:

    1.  Implement and compile a demo assembly (with or without Visual Studio).
    2.  Deploy the compiled assembly.
    3.  Develop and test the demo assembly.
    4.  Improve deployment and security.

    The demo assembly that will be used in this article will be kept very simple and is only intended as a visualization of the principles.

    Implement and Compile a Demo Assembly (with or without Visual Studio)

    The demo is based on a small assembly that only implements one type (class) that contains properties, a constructor and a method. Use your favorite text editor to create the C# file “DemoAddin.cs” containing the following code:

    // Copyright © Microsoft Corporation. All Rights Reserved.
    // This code released under the terms of the
    // Microsoft Public License (MS-PL,

    namespace DemoAddIn
        using System;
        public class DemoAddIn
            /// <summary>
            /// Private field where the constructor stores the name of the 
            /// demo object.
            /// </summary>
            private readonly string demoName;
            /// <summary>
            /// Gets the private read only field demoName.
            /// </summary>
            public string DemoName { get return demoName; } }
            /// <summary>
            /// Backing field for the property
            /// </summary>
            private string getSetProperty;
            /// <summary>
            /// Gets or sets a property using a backing field. Don’t return null values to AL
            /// as this can give unpredictable results.
            /// </summary>
            public string GetSetProperty
                get return getSetProperty ?? String.empty; }
                set { getSetProperty = value; }         }           /// <summary>         /// Initializes a new instance of the DemoAddIn class and assign a value to the         /// demoName field.         /// </summary>         /// <param name="name">Name of the demo object.</param>         public DemoAddIn(string name)         {             demoName = name;         }           /// <summary>         /// Sample function that illustrate how to use function parameters and          /// return data.         /// </summary>         /// <param name="arg">Function parameter</param>         /// <returns>The function arguemnt value or the constant string Empty if the          /// parameter is null or empty.</returns>         public string FunctionWithArgument(string arg)         {             return String.IsNullOrEmpty(arg) ? "Empty" : arg;         }     } }

    The assembly can be compiled from any C# compiler, and two common setups are shown below:

    Visual Studio

    Create a new solution and project named “DemoAddIn”. The project must be created using the template type “Class Library”. By default, you will have a file called class1.cs, which can be deleted from the project. Add a new C# file to the project and implement the class listed above. It should not be necessary to change any project options and when you can build the output successfully, you are ready to deploy the assembly to the NAV clients and server. For information on how to create new C# projects in Visual Studio, please refer to the MSDN guide How to: Create Solutions and Projects.

    Note: If you use Visual Studio 2010, please make sure that the target framework is set to .NET Framework 3.5 or 2.0.X. Microsoft Dynamics NAV 2009 R2 does not support assemblies compiled for .NET Framework 4.0. The framework version is set using the project properties and can be found in the Application tab.

    The compiled output will be stored in a folder named “bin\Debug” beneath the project folder.

    .NET Framework Compiler

    The framework compiler is a simple command line tool that is installed together with the framework and is available on all machines that uses .NET Framework.

    1. Open a command prompt and navigate to the folder containing the DemoAddin .cs file
    2. Compile the file using the command (replace Framework64 with Framework if the compilation takes place in a 32 bit OS).

    %windir%\Microsoft.NET\Framework64\v2.0.50727\csc.exe /debug /target:library DemoAddIn.cs

    This will create two files in the current directory.

    1. DemoAddIn.dll, which is the assembly
    2. DemoAddIn.pdb, which contains symbol and debug information

    When the assembly is final, then remove the /debug flag and add the desired optimizations. If the symbol file is desired, then add the option /debug:pdbonly.

    Deploy the Compiled Assembly

    The two files generated in the previous steps have to be deployed to the Add-ins folders within the product folders (it’s most convenient if the files are stored in a subfolder within the Add-ins folder; use the name DemoAddIn for the target folder):

    1. Design time using the Microsoft Dynamics NAV Classic Client.
      %ProgramFiles(x86)%\Microsoft Dynamics NAV\60\Classic\Add-ins\DemoAddIn
    2. Server service
      %ProgramFiles(x86)%\Microsoft Dynamics NAV\60\Service\Add-ins\DemoAddIn.
    3. The Microsoft Dynamics NAV RoleTailored client
      %ProgramFiles(x86)%\Microsoft Dynamics NAV\60\RoleTailored Client\Add-ins\DemoAddIn.

    The environment variable %ProgramFiles(x86)% will point to the Program Files folder that is used for 32 bit applications in a 64 bit operating system. If the current operating system is 32 bit, then use %ProgramFiles%, which by default points to C:\Program Files.

    Deployment during development of the Add-in assembly will be easier if a script like the following is created in the project folder:

    @echo off

    set AssemblyBase=DemoAddIn

    set root=%ProgramFiles(x86)%
    if "%ProgramFiles(x86)%" == "" set root=%ProgramFiles%

    call :deploy %AssemblyBase% "%root%\Microsoft Dynamics NAV\60\Classic"
    call :deploy %AssemblyBase% "%root%\Microsoft Dynamics NAV\60\Service"
    call :deploy %AssemblyBase% "%root%\Microsoft Dynamics NAV\60\RoleTailored Client"
    goto :EOF


    set AddInfolder="%~f2\Add-ins\%~1"
    if not exist %AddInFolder% mkdir %AddInFolder%
    if exist %~1.dll copy %~1.dll %AddInFolder%
    if exist bin\debug\%~1.dll copy bin\debug\%~1.dll %AddInFolder%

    if exist %~1.pdb copy %~1.pdb %AddInFolder%
    if exist bin\debug\%~1.pdb copy bin\debug\%~1.pdb %AddInFolder%

    goto :EOF

    It will copy the assembly and symbol files to the respective Add-in folders. If the project is being managed by Visual Studio, the script can be called from the PostBuildEvent so the binaries are deployed automatically on every successful build. Notice that the NAV server and client must be stopped before a new version is deployed as the application will keep the files locked until they are stopped. It’s not possible to update any Add-in assembly while a previous version is loaded as the OS will lock the files as soon as an application has loaded it. Adding this to the deployment script can be an option, but care should be taken so data isn’t lost (don’t kill the wrong client or server). 

    Develop and Test the AL Codeunit that Uses the Demo Assembly

    Create a new codeunit in the Classic client and name it 'Demo AddIn' (use a free objectid in the 50.000-100.000 range).

    In the OnRun trigger create the following variables:

    Name DataType Subtype Length
    demoAddIn DotNet DemoAddIn.DemoAddIn
    demoString DotNet System.String (mscorlib)
    textVar Text 512
    intVar Integer

    Note: for the Subtype of the DotNet DataType variables, use the assembly picker to select the DemoAddIn assembly from the “Dynamics NAV” tab and choose the type DemoAddIn.DemoAddIn from the “.NET Type List” that appears when the assembly is selected.

    The sample code utilizing the demo AddIn can be implemented as:

    // Copyright © Microsoft Corporation. All Rights Reserved.
    // This code released under the terms of the
    // Microsoft Public License (MS-PL,

    // Create an instance of the DemoAddIn type. The constructor takes a string argument
    // which is used to initialize an internal variable.
    demoAddIn := demoAddIn.DemoAddIn('Input data');

    // Use the property 'DemoName' to read the name set in the constructor.
    MESSAGE('DemoAddIn contains  %1', demoAddIn.DemoName);

    // Test that the property ‘GetSetProperty’ contains an empty string
    if not demoString.IsNullOrEmpty(demoAddIn.GetSetProperty) then
      error('The uninitialized property should return an empty string');

    // Use the property setter to assign an AL string to the internal CLR string variable.
    demoAddIn.GetSetProperty := 'Value set with property';

    // Read the property and see that the value has been set accordingly.
    MESSAGE('DemoAddIn contains  %1', demoAddIn.GetSetProperty);

    // Call a function in the AddIn that takes a string argument and returns the string
    // given in the argument.
    textVar := demoAddIn.FunctionWithArgument('Using FunctionWithArgument to change data');
    MESSAGE('Argument data is %1', textVar);

    Compile the codeunit in the classic client and run it through the Microsoft Dynamics NAV RoleTailered client (RTC). As it’s hard to run codeunits from the RTC client, it can be convenient to create a small page object from which a codeunit can be run.

    The sample primarily uses types from the demo add-in, but uses also a method from the CLR String class to check the validity of a string value. Typical scenarios involve types from both user defined assemblies and the Framework libraries (very often from mscorlib, System, System.Xml). If you don’t know which assembly implements a given type, you can get the information from the MSDN online library on Do a search for the type in the library and find the Assembly specification on the page the documents the class implementing the type.

    Example: Search for System.String and select the first entry in the search results (will be “String Class (System)”). From the screen shot below, it’s seen that the String type is defined in the assembly “mscorlib”.

    Suggested Reading

    The MSDN documentation for Microsoft Dynamics NAV R2 contains an Update guide which documents the .NET interop feature in R2 and gives a couple of examples of simple use cases. See for more information.

    Another helpful source is the discussion forum on

    - Niels-Henrik Sejthen

Page 1 of 1 (10 items)