• Microsoft Dynamics NAV Team Blog

    Using Web Services to Access Microsoft Dynamics NAV 5.0



    Dynamics NAV 2009 contains a new subsystem for dealing with Web Services. This feature has been well received by partners and customers alike. Partners have expressed interest in having web services available for earlier versions of Dynamics NAV. This feedback resulted in a technology talk at Directions2007 in Florida, where the topic was what could be done to day. The conclusion of the talk was that everything we where intending to deliver was already possible today, yes some code is needed but strictly from function/feature perspective all of it is possible, and it is not even all that ugly. Dynamics NAV 2009 will provide out-of-the-box programmatic web service access to the application and will therefore remove the need for this additional technology plumbing described here.

    I have to say that the response to my talk has been tremendous. After the response to my talk on Web Services in NAV 5.0 and previous versions I decided to write this blog post and make the source files available.

    This post is about how to bridge the gap between the need for web services now and the current platform, it will help you understand how you can provide Web Services directly from Dynamics NAV today, in a “simple” and flexible way, already today.

    To work with the samples in this post you will need: Visual Studio 2005, Dynamics NAV 5.0 and .Net 3.0 installed on your system. This sample should work on Dynamics NAV 4.0 to but has not been tested on that version.


    The system we will build contains 4 different components/moving parts: Web Service Listener, Event Dispatcher, Codeunit Eventhandler and XMLPort for stream handling.


    Web Service Consumer

    Any client that understands how to communicate with Web Services; like InfoPath, Visual Studio, SharePoint or any custom application written by you.


    Is the physical communication port that the WCF listens to.

    WCF Web Service

    Defines the data contracts and service contracts for the Web Service, it also implements the concrete service and opens for listening in the WCF subsystem, it then delegates the requests to the COM Event Dispatcher component.

    COM Event Dispatcher

    This component provides the hookups for Dynamics NAV, both to activate the service and to register event sinks. It defines 2 IDispatch interfaces the IServiceEvents and the IWebServiceListner, as well as the concrete implementation of the IWebServiceListner in the WebServiceListner class that provides the actual code for hooking up the WCF Web Service to Dynamics NAV.


    We are using the CLR runtime for writing our Web Service component and our COM plugin. Some of this blog entry is about interop between Dynamics NAV and .NET through COM.

    Codeunit Event Handler

    Is responsible for starting up the WCF Web Service through the COM interface, it then registered for events coming from the WCF Web Service Component. The events routed to XMLPort for processing.

    XMLPorts for datastreams

    It deals with the actual business logic and data coming from or going to the Web Service.


    The implementation is in 2 programming languages: C# and C/AL.

    Please take a look at the provided code sample, for the rest of the information contained in the posting. It can be found here: http://code.msdn.microsoft.com/nav/Release/ProjectReleases.aspx?ReleaseId=896

    I have included comments in the code that should explain what is going on, if you feel something is missing, first look at the documentation for the WCF or post a comment to this post and I will try to answer it.

    Deployment of Sample

    To deploy the sample you will first have to download it, unpack it.

    Then open it up with Visual Studio and compile.

    Then import the codeunit.txt and xmlport.txt into your NAV installation and compile those objects, starting with the XMLPort

    To run the service simply open the Object Designer in NAV, find the Codeunit that you just imported and press run.

    There is no dependency on IIS or other external components. No further deployment steps should be needed.

    In the Visual studio solution is a ConsoleTestApp project. After you have followed the steps above you can run that project, it will test if your install was successful, as well as provide sample on how to use the web service.

    Special considerations

    In this sample I’m using XMLPort to handle the XML stream that is provided.

    You can take many different approaches to this, and still reuse large please of the code provided in the sample.

    To use the XMLPort as handler you will have to set the encoding property to UTF-8. This is due to a null termination bug in stream handler in NAV.



    With this approach you can already today, incorporate web services in your projects in straightforward way.

    The appropriate usage is whenever you need to give external application access to Dynamics NAV data or business process.

    For any questions or comments please feel free to ask them in the comment section of this blog post.  I will answer questions to best of my ability on this post in the comments section as well.

    One last thing:  This is a sample code.  It has not been tested, you should thoroughly test this code before usage.

    Best regards,
    Kris Rafnsson

  • Microsoft Dynamics NAV Team Blog

    Microsoft Dynamics NAV/SQL Server Configuration Recommendations


    Michael De Voe, a Senior Premier Field Engineer at Microsoft, has compiled a set of recommendations for SQL Server configuration to improve performance when running Microsoft Dynamics NAV 5.0 and later versions with one of the following versions of SQL Server:

    • Microsoft SQL Server 2005 SP3 x64
    • Microsoft SQL Server 2008 SP1 x64
    • Microsoft SQL Server 2008 R2 x64

     The attached document contains Michael's recommendations, including the following options and parameters:

    • Max Server Memory
    • Auto-Create Statistics
    • Auto-Update Statistics
    • Auto-Grow
    • Database Compatibility Level
    • Trace Flag 4136
    • Trace Flag 4119
    • Data files for TempDB
    • Disk Alignment
    • Read Committed Snapshot Isolation (RCSI)
    • Max Degree of Parallelism
    • Dynamics NAV Default Isolation Level
    • Dynamics NAV "Lock Timeout"
    • Dynamics NAV "Always Rowlock"
    • Maintenance Jobs
    • Instant File Initialization
    • Optimize for Ad Hoc Workloads
    • Page Verify
    • Lock Pages in Memory

     These postings are provided "AS IS" with no warranties and confers no rights. You assume all risk for your use.

  • Microsoft Dynamics NAV Team Blog

    Visual Studio 2010 and SSRS (RDLC) reports in NAV 2009


    A couple of weeks ago Microsoft Visual Studio 2010 was released. Unfortunately we will not be able to support Visual Studio 2010 in Dynamics NAV 2009 when developing SSRS (RDLC) reports.

    When you are designing RDLC reports in NAV 2009 you are creating reports in a format known as the “RDL 2005” format.
    Both Visual Studio 2005 and 2008 supports this format, but not Visual Studio 2010. Visual Studio 2010 is able to open the “RDL 2005” format but will immediately convert the report to “RDL 2008” format. This conversion gives us the some challenges:

    1. To view an “RDL 2008” format report you will need to have to have the “Microsoft Report Viewer 2010” installed on all Role Tailored client (RTC) machines, currently the “Microsoft Report Viewer 2008” is installed by the NAV 2009 installation program.
    2. If we opened up for Visual Studio 2010 you will convert the reports you design to “RDL 2008” format, and leave the unopened reports in “RDL 2005” format. So i.e. are developing an add on and share this with other partners you will need to inform these partners that Report Viewer 2010 is a requirement for all RTC machines. And if these partners are to modify any of your reports, Visual Studio 2010 is a requirement as well.
    3. We need change our code to now compile to “RDL 2008” format when importing the RDLC layout back to NAV.

    So to avoid this confusion we will not open up for Visual Studio 2010 support before our next major version of Dynamics NAV.

    If you for other reasons want to use Visual Studio 2010 you can easily have Visual Studio 2008 and Visual Studio 2010 installed on the same machine. We will just open the Visual Studio 2008 version when you select “View / Layout” in the Object Designer.

    If you only have Visual Studio 2010 installed you will see this message:

    An error occurred when opening Report Designer. A supported version of Visual Studio could not be found.

    This is the same message you get when you have no Visual Studio installed, because we search for the following Visual Studio versions and in prioritized order. So in case you have both Visual Studio 2005 and 2008 installed, we will use the 2008 version:

    1. Microsoft Visual Studio 2008
    2. Microsoft Visual Web Developer 2008 Express edition with SP1.
    3. Microsoft Visual Studio 2005 with SP1
    4. Microsoft Visual Web Developer 2005 Express edition with SP1.

    In a previous blog post I outlined the Visual Studio options you have for designing RDLC reports for NAV 2009, and this list is still valid.

    Hint: If you are using Windows 7 and want to use “Microsoft SQL Server 2008 Express with Advanced Services ” you need to install “Microsoft SQL Server 2008 R2 Express with Advanced Services” to have a successful installation.


    Claus Lundstrøm, Program Manager, Microsoft Dynamics NAV

  • Microsoft Dynamics NAV Team Blog

    Creating a web service manually, the importance of the name you give it, and a few small things to remember


    When you use the SC command line command to create a new NAV 2009 Service, how does the new service know whether it is a middle tier for RTC to connect to, or whether it is supposed to handle web service calls?

    In other words, what decides whether the new service will be "Microsoft Dynamics NAV Server" or "Microsoft Dynamics NAV Business Web Services"?


    It depends on the name. If it starts with "MicrosoftDynamicsNavWS", then it will be for Web Services. If the name starts with anything else, then it will be for middle tier for RTC clients.


    To keep things simple, just give your NAV Servers names beginning with MicrosoftDynamicsNAV / MicrosoftDynamicsNAVWS. Then if you need a second, third, etc server, add a unique name, seperated by a $-sign, for example:




    Here are the simple steps for how to create a new web service service, and a few more things to be aware of. Let's say that we want to start a second set of NAV Servers.


    First create the normal service from a command prompt:

    SC CREATE "MicrosoftDynamicsNAV$Svr2" binpath= "C:\Program Files\Microsoft Dynamics NAV\60\Service2\Microsoft.Dynamics.Nav.Server.exe" DisplayName= "MSSvr2"

    Then create the service for Web Services: 

    SC CREATE "MicrosoftDynamicsNAVWS$Svr2" binpath= "C:\Program Files\Microsoft Dynamics NAV\60\Service2\Microsoft.Dynamics.Nav.Server.exe $Svr2" DisplayName= "MSWSSvr2" type= share


    The additional settings you must provide as marked in bold above, and a few things that you must remember are:


    1)  The Name

    As described, the name must begin with MicrosoftDynamicsNAVWS if you want it to be for web services


    2)  Include the last part of the name in BinPath

    After the .exe in the binpath parameter you must specify the part of the name ($Svr2 in this case) that comes after MicrosoftDynamicsNAVWS. If you forget this step, you might get this error when you try to start the service:

    Windows could not start the MSWSSvr2 service on Local Computer.Error 1083: The executable program that this service is configured to run in does not implement the service.


    3)  Type must be share

    For the service that handles web services, add the parameter type= share. Otherwise the service will still try to start up as a middle tier (not for web services).


    4)  Spaces after =

    You must remember the space after each = in the command, as in for example "type= share". This is just the syntax of the SC-command.


    5)  DisplayName

    It doesn't matter what display name you give - this is just to find it in Services.


    These are just some of the small things to keep in mind. For many more details on web services go to Freddys blog, especially this post:

    Multiple Service Tiers - SP1


    // Lars Lohndorf-Larsen


  • Microsoft Dynamics NAV Team Blog

    Send email with PDF attachment in NAV 2009


    In this post I would like to explore the possibilities to create an email from the Role Tailored client and attach an invoice as a PDF file to the email, unfortunately we have do not have this functional build into our Demo application, but let me show you how this can be do with little effort.

    First I suggest you download the fob file which contains the 5 different options I will go through here.

    When downloaded the fob file you will see that I have added 5 new actions


    1. SendAsPDF(Use of codeunit to rename) recommended solution
    2. SendAsPDF(Access to Server needed)
    3. SendAsPDF(With Temp file name)
    4. SendAsPDF(User prompted to save)
    5. SaveAsPDFrecommended solution(if you just want the PDF file)

    Let me go through the different options starting from the bottom, since I recommend option 1, but I would also like to share other options for doing this, since these might be valuable for you.

    Option 5: SaveAsPDF
    In this option you will get prompted if you want to open or save the PDF. The PDF file created will be based on the select Invoice in the Posted Sales Invoices List Place


    In this option all I do is to have the server create the PDF file for me and use the new download function in NAV 2009 to retrieve the PDF file created on the server.

    Option 4: SendAsPDF(User prompted to save)
    In this option, you will first be prompted to save the file.
    Here it is important to select to “”SAVE” the PDF file on the disk, to have the correct name of the PDF file. If you select to “OPEN” the PDF filename will be given a temp name.

    After you have saved the PDF we now create the email message you will get 3 messages similar to this when this happens:


    You get these message because we connect to an external component(Outlook) to the Role Tailored client. It is of course up to you if you want to set this to “Always allow”, but this would remove these messages, the next time you open the Role Tailored client.

    When you have allowed these to run, email will be created with the PDF file attached.


    In this option all I do is to download the PDF to the client and then use the Mail codeunit to create the email

    Option 3: SendAsPDF(With Temp file name)
    In this option, you will not be prompted to save the PDF file.
    And the email will be created immediately. This would probably be the preferred compared to downloading this to the user disk, but we will use the PDF file created on the server, and since this file get a TEMP name, like this: “__TEMP__570eb0279b9d4b1fa837caf3a14acbf7” this option is not really good.

    Let us look at the option 1 and 2 where this issue is solved.

    Option 2: SendAsPDF(Access to Server needed)
    In this option you will not be prompted to save the file either, but here the end user will need to have access the server folder where the PDF is stored on the server. In some situation you might want this, but for security reasons you might also not want to give this access to the user.

    Option 1: SendAsPDF(Use of codeunit to rename) recommended solution
    Again in this option you will not be prompted to save the PDF file, but the PDF file will be automatically added to the email. In this option we have build a codeunit to rename the TEMP file created on the server, and end user will not need to have access to any folders on the server.

    So all in all I recommend option 1 for attaching PDF file to an email. And once again I have made all the code available here, so feel to be explore how I build this. If you feel there is an option that I missed, feel free to leave a commit or use the contact form Email.

    Claus Lundstrøm, Program Manager, Microsoft Dynamics NAV

  • Microsoft Dynamics NAV Team Blog

    Using XMLports With Web Services


    As a follow-up on my recent webcast (found HERE), here is the general walkthrough of how to create an XMLport and use it for sending data to NAV.

    First, what we want to do is create our XMLport and make sure it has the elements and values that we want.


    For the root element, I have set maxOccurs = 1 to avoid any confusion.
    For the general XMLport, the UseDefaultNamespace and the DefaultNamespace values have been edited as seen below.


    Other than that, I have no code on my XMLport, but naturally, anything goes that would work on a regular XMLport. Now to the Codeunit:

    ImportDim(VAR DimImport : XMLport DimImport) Return : Text[30]
    EXIT('Import Run');

    So basically we’re telling the XMLport to run an import and we’re returning to the Web Service that we’ve run. All we need to do now is expose the Web Service using Form 810:


    Remember that the actual name of the codeunit does not have to match that of the service name here.

    So now we move over to Visual Studio and start working with what we have. The first thing we’ll notice is that the WSDL matches our XMLport.


    What we see is both the RootDimensions element which consists of multiple Dimension elements. From there, we can see the definition of the Dimension element the fields we’ve chosen to expose.

    When creating a new project, we will go with a Windows Forms project this time.


    And from there we will start off by adding a web reference to http://localhost:7047/DynamicsNAV/WS/Codeunit/DimensionImport .

    The details on how to add a web reference can be found in the Developer and IT Pro Documentation.

    On my new form, I have created two input boxes for the Code and Name of the dimension and a Create button.


    And then we have the code on the Create button, along with helpful comments:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms; 


        using WSDI; 
        public partial class Form1 : Form 




            public Form1() 
            private void button1_Click(object sender, EventArgs e) 
                //Make sure the ResultLabel doesn't have any text on multiple runs 
                ResultLabel.Text = ""

    //Create a WS reference instance, set credentials and define the company by specifying the URL. 
                DimensionImport NAVImport = new DimensionImport(); 
                NAVImport.UseDefaultCredentials = true
                NAVImport.Url = "http://localhost:7047/DynamicsNAV/WS/CRONUS%20International%20Ltd/Codeunit/DimensionImport"
                //First we create our root element 
                RootDimensions RootDim = new RootDimensions();




                //Then we create a List to handle our (possible) multiple dimensions 
                List<Dimension> DimList = new List<Dimension>();




                //And then we create a single dimension 
                Dimension Dim = new Dimension();  


                if (dimInputCode.Text != "" && dimInputName.Text != ""
                    //We assign the values from our textboxes to the single dimension 
                    Dim.DimensionCode = "AREA"
                    Dim.Code = dimInputCode.Text; 
                    Dim.Name = dimInputName.Text;




                    //Then we add the single dimension to our list 


                    //To get the list of dimensions "attached" to the root element, we use the following
                    RootDim.Dimension = DimList.ToArray(); 
                        //Then we send to NAV and show our result 
                        ResultLabel.Text = NAVImport.ImportDim(ref RootDim);




                    catch (Exception ex) 
                        //Show a possible exception 
                        ResultLabel.Text = ex.ToString(); 
                    //Make sure there are values 
                    ResultLabel.Text = "Both values must be filled"

    Our wonderful application is now ready to run and all we have to do is press F5:


    We have now created our XMLport, exposed it using a codeunit and set data into it from a form based application.

    Lars Thomsen

    Microsoft Customer Service and Support (CSS) EMEA

  • Microsoft Dynamics NAV Team Blog

    Error 1935 when installing Dynamics NAV 5.0 SP1


    When I tried to install the NAV 5.0 SP1 client I ran into an error 1935. This may happen on Vista and Windows 2008.

    Error 1935; an error occurred during the installation of
    assembly component {98CB24AD-52FB-DB5F-A01F-C8B3B9A1E18E}. HRESULT:0×800736CC.

    The solution is simpler then it seems. You need to install Microsoft Visual C++ 20005 SP1 Redistributable pack. Remember if you are running on a 64 bit system you need to install both x86 and x64 package.


  • Microsoft Dynamics NAV Team Blog

    Updated: How to log report usage


    Updated: Now with links to both NAV 5.0 and NAV 2009 hotfixes

     /Claus Lundstrøm


    In several partners meetings I have heard this requests over and over again.

    Claus, when we are planning an upgrade of Classic reports to RDLC reports, we do not always know which reports are actually being used at the customer site. It would be great to be able to log which reports are used so we know exactly which reports we need to upgrade to RDLC.

    Well, if you download below hotfix you will now have the capability to log report usage at a customer site.

    Dynamics NAV 5.0: KB2575296

    Dynamics NAV 2009: KB2558650
    Find links to all NAV 2009 Platform Hotfixes here:
    CustomerSource: Overview of Released Platform Hotfixes for Microsoft Dynamics NAV 2009 SP1 and Microsoft Dynamics NAV 2009 R2
    PartnerSource: Platform Hotfixes for Microsoft Dynamics NAV 2009 SP1 and Microsoft Dynamics NAV 2009 R2


    In the following steps I have outlined which steps you need to do to get this log file. Remember above hotfix is required to perform the following steps.

    1. Create new table to be used for Log report usage:


    OBJECT Table 50000 Report Log
    Version List=CLAUSL;
    { 1 ; ;No. ;Integer ;AutoIncrement=Yes;
    MinValue=1 }
    { 2 ; ;User ID ;Code50 ;TableRelation="User Role"."Role ID";
    CaptionML=ENU=User ID }
    { 3 ; ;Report ID ;Integer ;CaptionML=ENU=Report ID }
    { 4 ; ;Report Name ;Text249 ;FieldClass=FlowField;
    CalcFormula=Lookup(AllObjWithCaption."Object Caption" WHERE (Object Type=CONST(Report),
    Object ID=FIELD(Report ID)));
    CaptionML=ENU=Report Name }
    { 5 ; ;Date Time ;DateTime }
    { ;No. ;Clustered=Yes }

    2. Now with the table created for our Report Usage log please open Codeunit 1

    3. Open “C/AL Globals”

    4. Navigate to ”Functions”


    5. Create new function with Name=”OnReportRun”


    6. Open Properties and change ID to 120


    7. Now open “Locals” and create parameter= ReportId with Type=Integer


    8. Select Variables tab and create ReportLog


    9. Now all we need is to write the code for this new trigger. Open C/AL Editor and navigate to the end.

    10. In OnReportRun write the following code:

    ReportLog."User ID" := USERID;

    ReportLog."Report ID" := ReportId;

    ReportLog."Date Time" := CURRENTDATETIME;



    11. Now Restart Classic Client

    12. Run a couple of reports

    13. And then at last run the Report Log table to see the result:


    Yes I’m aware that this solution only works for Classic Reports, and yes I also would like a feature so it’s possible for you to log all objects being used at a customer site. For now we do not get this, but let’s see what the future brings.

    /Claus Lundstrøm

  • Microsoft Dynamics NAV Team Blog

    Microsoft Dynamics NAV Compatibility with Microsoft Office 2010 and Microsoft SharePoint 2010


    With the release of Office 2010 and SharePoint 2010 the relationship between internal line of business applications and business productivity software is stronger than ever. There have been added many exciting new features, which will bring value to many customers, including those customers that are using Microsoft Dynamics NAV today.

    User Interface

    The user interface (UI) is the "face" of a software application - A good user interface is intuitive, familiar, and easy to use. It improves productivity by minimizing the number of clicks required to get a task done. This is what we accomplished with the release of the RoleTailored client in Microsoft Dynamics NAV 2009. The Fluent UI is now used by all Microsoft Office programs as well as SharePoint Server 2010, and does away with menus, which were growing increasingly complex, replacing them with a clear set of icons that are relevant to the task being performed.

    With the 2010 release, Microsoft Office, Microsoft SharePoint Server, and Microsoft Dynamics now share this strong "facial" resemblance, making them more consistent to use and easier to adopt.


    Just as beauty is more than skin deep, so the ties between Microsoft Dynamics and Microsoft's business productivity infrastructure run deeper than just the UI.  Business Connectivity Services (BCS) is a new technology that crosses Microsoft Office 2010 and Microsoft SharePoint Server 2010, and can be thought of as "plumbing" for connecting business applications through Web Services in Microsoft Dynamics NAV 2009 with SharePoint and Office. This is no ordinary plumbing, though, as it enables some powerful new scenarios for Microsoft Dynamics NAV customers, including the ability to update information stored in a Microsoft Dynamics NAV database directly from a SharePoint site, and making it easier to take Microsoft Dynamics NAV information offline through either Outlook 2010 or SharePoint Workspace 2010. 


    The majority of Microsoft Dynamics customers use Microsoft Excel to analyze their business information. PowerPivot for Microsoft Excel 2010 offers the ability to quickly create PivotTables or PivotCharts that are pulling in data from Microsoft Dynamics ERP or CRM in real time. New Excel 2010 features such as Slicers and Sparklines can then be added to bring the numbers to life and gain deeper insights into what's happening in the business.  


    Since Microsoft Dynamics NAV always has had a strong integration to the Office and SharePoint products, we are proud to announce that Microsoft Dynamics NAV 2009 SP1 and Microsoft Dynamics NAV 5.0 SP1 Update 2 are compatible with Microsoft Office 2010 and Microsoft SharePoint 2010!

    The details in the support for the different Office and SharePoint integrations are listed below. Please note that Office 2010 is available in both a 32-bit version and a 64-bit version, but some NAV areas are currently not supported in the 64-bit version. The recommended version of Office 2010 in combination with NAV is the 32-bit version. Further reading on the difference between the two versions can be found here: http://blogs.technet.com/b/office2010/archive/2010/02/23/understanding-64-bit-office.aspx.  

    1. Employee Portal is supported for SharePoint 2010. However please look at KB970502 for instructions on how to install in a 64-bit environment.
    2. Sending data from Microsoft Dynamics NAV to both Word and Excel using the basic export is fully compatible with Microsoft Office Word 2010 and Microsoft Office Excel 2010. The same applies exporting to Excel from reports and to Export of budgets, Analysis Schedules etc.
    3. Interactions such as letters can be initiated from Microsoft Dynamics NAV and stored as appropriate in Microsoft Office Word 2010 in both 32-bit and 64-bit version.
    4. Sending emails from Microsoft Dynamics NAV is compatible with Outlook 2010 32-bit version, but is currently not supported for the 64 bit version.
    5. Outlook Synchronization is compatible with Outlook 2010 32-bit version. The installation and the add-in is not currently supported for the 64- bit version.
    6. Email logging is dependent on CDO, which is not supported in Office 2010. Please read http://support.microsoft.com/kb/2028411. A possible workaround has been identified by manual installing CDO in combination with KB2291071, but it is recommended to stay on Office 2007 if email logging is required.
  • Microsoft Dynamics NAV Team Blog

    Automation Objects in Microsoft Dynamics NAV 2009



    The Automation object is often used to integrate NAV business logic with external processes and thereby extend the functionality of the product, such as integration with other products like Office. Automation objects must expose a COM interface, and every time we cross a process boundary is worth thinking about performance, but issues that involve correct operation could have a negative impact on performance. This is something we are willing to accept. One example is that objects designed for a single thread execution must execute on Single Threaded Apartment (STA) threads. Having a look at this KB article (http://support.microsoft.com/kb/257757/) explains why office products never should be allowed to run on the server:

    Reentrancy and scalability: Server-side components need to be highly reentrant, multi-threaded COM components that have minimum overhead and high throughput for multiple clients. Office applications are in almost all respects the exact opposite. Office applications are non-reentrant, STA-based Automation servers that are designed to provide diverse but resource-intensive functionality for a single client. The applications offer little scalability as a server-side solution. Additionally, the applications have fixed limits to important elements, such as memory. These cannot be changed through configuration. More importantly, the applications use global resources such as memory mapped files, global add-ins or templates, and shared Automation servers. This can limit the number of instances that can run concurrently and can lead to race conditions if the applications are configured in a multi-client environment. Developers who plan to run more than one instance of any Office application at the same time need to consider "pooling" or serializing access to the Office application to avoid potential deadlocks or data corruption.”



    Flavors of COM

    Apartment threading

    There are two major flavors of Automation objects, ones that are designed for single threaded applications, and ones that execute well in a multithreaded environment. This doesn’t prevent one from running STA objects on the server and MTA objects on the client, but each scenario where “best practices” are deviated should be considered closely.

    An example would be the XML Document object


    The DOMDocument is a single threaded apartment version and the FreeThreadedDOMDocument is the version that utilizes a multithreaded environment, like the server. But in cases where we a free threaded version of the object is not available, it would properly be acceptable to use the version available, because the .Net runtime is managing MTA-to-STA marshaling behind the scene. This could result in bad performance and other problems – but in most scenarios it is likely to work. A closer look at “PRB: MSXML Performance Bottleneck in ShareMutex Under Stress” explains why issues like these must be considered.

    “Using the MSXML parser in a high-stress environment … may cause unusually long run times on XML requests, and the application or service can appear to stop responding (hang).“

    And the solution in this scenario would be to use the FreeThreadedDOMDocument object on the server.

    Native and Managed Automation Objects

    The Automation implementation in the Role Tailored Client and the Dynamics NAV Server utilizes the CLR implementation, and the CLR does an excellent job of allowing managed code to call out to unmanaged Automation objects. It generates a runtime-callable wrapper (RCW) proxy that implements all of the interfaces of the underlying object. Furthermore, the CLR has a built-in mapping/marshaling layer that knows how to translate the types between the native and managed domains.

    The following table shows the specific type mappings between AL, COM and their corresponding .NET types.


    All the Automation objects are late bound activated; this means that they must implement the IDispatch interface, in order for the Reflection API to be able to invoke members. Managed Automation objects are recognized by the RCW as being managed and standard CLR reflection invocation takes place. Therefore, in-process (dll) and Out-of-process (exe) Automation behaves identically if the objects are created in a managed language.


    The default account for running the NAV Server, configured at installation time, is the built-in Network Service account. This account does not have permissions to spawn a new process, as configured in Component Services, and it is not recommended to change that behavior. This is by design, in order to prevent out-of-process Automation servers (Executables with a COM Interface) to execute on the server. But if the scenario requires this, it would be a recommended practice to create a new service account with the minimum privileges plus the “Launch and Activate Permissions” of the required Automation Servers. These processes will then be created on the server and properly stays alive until they receive a specific terminate command, or the server is rebooted. Another risk with Automation servers on the NAV Server machine is that users could potentially share the same Automation process. In AL, the construct CREATE (automationServer, TRUE), will search the system for created instances of type “automationServer” and try to reuse that process, and potentially read data created by another user.

    Therefore the recommended syntax would be CREATE(automationServer, FALSE, FALSE), for Automation servers running on the NAV Server. On the client tier, no sharing can occur and it would be perfectly fine to try and reuse the Automation server.

    The in-process Automation objects whether they are created on the client or server tier are hosted by the running process and inherit the security context of the active user. The same goes for OCX controls that require an UI and therefore only will be allowed on the client side.

    Wrap-up (recommendations)

    Server tier
      • Native Automation objects: In-process automation servers, like MSXML6.dll.
      • Objects with a user interface such as OCX types.
      • Managed wrapped COM Objects
      • Objects designed for multi threaded execution (MTA)
    Client tier
    • Native Automation objects: Out of process automation servers, like Microsoft Office.
    • Objects with a user interface such as OCX types.
    • Objects designed for single threaded execution (STA)
    • It is good practice to design your Automation interfaces to get as much work done in a single method invocation. And when consuming a component, try to use it in way that minimizes chattiness. This is utmost importance for the client side automation scenario.


    COM is an immutable, interface-based model. Interface design is very important and should always be split from the implementation. Try to avoid auto-generated interfaces based on classes as they have a tendency to violate this guideline and not version well. There is a good source of information at: “Do not use AutoDual ClassInterfaceType“


    (see the first comment on this post for the text of this sample)

    - Stefan Omdahl

  • Microsoft Dynamics NAV Team Blog

    Combined Hotfix Release for Microsoft Dynamics NAV 2009 SP1 and Microsoft Dynamics NAV 2009 R2


    Platform Hotfixes

    With the release of Microsoft Dynamics NAV 2009 R2, the release of platform hotfixes for Microsoft Dynamics NAV 2009 SP1 and Microsoft Dynamics NAV 2009 R2 has been combined. This means that there will be one set of hotfix files that can be used with both Microsoft Dynamics NAV 2009 SP1 and Microsoft Dynamics NAV 2009 R2.

    The combined hotfixes will start with build number 32074.

    Special note for Microsoft Dynamics NAV 2009 SP1

        In order to install hotfixes with build 32074 and higher, customers who have Microsoft Dynamics NAV 2009 SP1 with a build below 32074 installed, must first perform one of the following steps:

    1. Install hotfix 2496107 - Platform hotfix resource files for Microsoft Dynamics NAV 2009 SP1.

       For more information about the files that need to be installed and how to install the files, see KB 2496107

    1. Perform a solution upgrade to Microsoft Dynamics NAV 2009 R2

       For more information about how to perform a solution upgrade from Microsoft Dynamics NAV 2009 SP1 to Microsoft Dynamics NAV 2009 R2, see Install and Upgrade Instructions for Microsoft Dynamics NAV 2009 R2

    There are no prerequisites for customers who have Microsoft Dynamics NAV 2009 R2 installed.

    For a complete list of all platform hotfixes released for Microsoft Dynamics NAV 2009 SP1 and Microsoft Dynamics NAV 2009 R2, see the following pages on CustomerSource and PartnerSource:

    Note: There are no changes to the release process for platform hotfixes for Microsoft Dynamics NAV 2009 (no service pack).

    Application Hotfixes

    All application hotfixes released for Microsoft Dynamics NAV 2009 SP1 applies to Microsoft Dynamics NAV 2009 R2 as well.

    For a complete list of all application hotfixes released for Microsoft Dynamics NAV 2009 SP1 and Microsoft Dynamics NAV 2009 R2, see the following pages on CustomerSource and PartnerSource:

  • Microsoft Dynamics NAV Team Blog

    Transfooter and Transheader functionality in RDLC(SSRS) reports


    Please note that I have posted a new blog for this subject here. /Claus Lundstrøm

    In our Classic reports we have the possibility to use Transfooter and Transheader. A typical use for classic Transfooters and Transheaders are to show a current subtotals up to the end of the current page or sums per page

    These functions are not directly mapped from Classic reports to RDLC reports in Dynamics NAV 2009, but in this post I will go through how this is done in RDLC reports:

    1. Create new report blank report with table 18


    2. Create DataItem ”Customer”


    3. Go to Section Designer and add the following fields:

    · No.

    · Name

    · Debit Amount


    4. Save the report as ID 50000 – Transfooter / Transheader


    5. Now go to Visual Studio (View / Layout)


    6. Create table and add the fields No, Name and Debit Amount


    7. Give this table the name “MainTable”


    8. Now we have added the basic for this report. But I would also like to have a Grand total of the Debit Amount so I add this as well. I add this in the Footer of the table

    ="GrandTotal: " & sum(Fields!Customer__Debit_Amount_.Value)


    9. Now if my report is printed I get a list of my all my customer with Debit Amount displayed and with GrandTotal in the end of the report:


    10. Now I would like to see the accumulated sum of the Debit Amount on each the page footers, and on the next page display this accumulated sum from previous page. So I will add Transfooter and Transheader functionality to the report.

    11. First we need to do some intermediate calculations to accomplish this.

    Add 3 new columns to the existing table in Visual Studio;


    12. In the first column enter this expression:

    =RunningValue(Fields!Customer__Debit_Amount_.Value, Sum, "MainTable")

    And give this name “Subtotals1”


    13. In the Second column enter this expression:

    =RunningValue(Fields!Customer__Debit_Amount_.Value, Sum, "MainTable") - Fields!Customer__Debit_Amount_.Value

    And give this name “Subtotals2”


    14. In the Third column enter this expression:

    =RunningValue(Fields!Customer__No__.Value, Count, "MainTable")

    And give this name “SubCount”


    The 3 columns should now look like this:


    15. As these 3 columns are only used for calculation I will make them really small and set Visibility “Hidden=True” and make the font red so I remember that these columns are hidden.

    Your report should now look like this:


    16. Ok, it’s now time to add a Transfooter and Transheader. Enable Page Header and Page Footer in the report. You report should look like this:


    17. In the Page Footer I place a text box with the following expression:

    ="Transfooter subtotal = " & Last(ReportItems!Subtotals1.Value)

    And then I set BackgroundColor, and Color just so this Transfooter stands out in my report, and right align text:



    18. In the Page header I place a text box with the following expression:

    ="Transheader subtotal = " & (First(ReportItems!Subtotals2.Value))

    And then I set BackgroundColor, and Color just so this Transfooter stands out in my report, and right align text:



    19. Now I’m almost done but I would like to not see the Transheader on the first page and not to see the Transfooter on the last page, so I select properties on the Page Header and set the “PrintOnFirstPage=False”


    20. Now I could do the same on Page Footer, but maybe I would like to display the Page Footer, but not with the Transfooter displayed, so here is a little trick for how to do this.

    21. Insert a text box below the table and set the expression to “=True”, Name=LastPageControl, Hidden=True and color red.


    22. With this field added after the table we can now check to see when we are on the last page.

    So I add the following Visibility Expression on the Transfooter textbox:



    23. Now I’m done, I save, import into NAV and compile. After some fit and finish on the report it now looks like this when I print:



    You can download my report here as FOB and XPS.

    Claus Lundstrøm, Program Manager, Microsoft Dynamics NAV

  • Microsoft Dynamics NAV Team Blog

    Transfooter and Transheader functionality in RDLC(SSRS) reports - revisited


    In one of our previous blog post we discussed the possibility to do Transfooter and Transheader functionality in RDLC(SSRS) reports and describes a viable solution for this in RDLC.

    In this blog post we would like to suggest an alternative, a bit more economical and easier to implement solution for the same problem.

    For the demo we use the same table and the same report and will strive to achieve the same results as in the mentioned in our previous blog post.

    1. Create new report blank report with table 18


    2. Create DataItem ”Customer”

    3. Go to Section Designer and add the following fields:

    • No.
    • Name
    • Debit Amount

    4. Save the report as ID 50000 – Transfooter / Transheader

    5. Now go to Visual Studio (View / Layout)

    6. Create table and add the fields No, Name and Debit Amount

    7. Give this table the name "MainTable"

    8. Now we have added the basic for this report. But I would also like to have a Grand total of the Debit Amount so I add this as well. I add this in the Footer of the table

    ="GrandTotal: " & sum(Fields!Customer__Debit_Amount_.Value)


    9. Now if my report is printed I get a list of my all my customer with Debit Amount displayed and with GrandTotal in the end of the report:

    10. Now I create a small block of VBS code in order to perform some calculations and store intermediate data

    Open “Report->Report Properties” dialog and select “Code” tab, enter the following VBS code:

    11. Define a hashtable for storing running accumulated sums for each page of the report

    Shared RunningTotals As New System.Collections.Hashtable

    12. Define two public functions, which populate and query the hashtable from above

    Public Function GetRunningTotal(ByVal CurrentPageNumber)

    Return IIF(CurrentPageNumber > 0, RunningTotals(CurrentPageNumber), 0)

    End Function


    Public Function SetRunningTotal(ByVal CurrentPageTotal, ByVal CurrentPageNumber)

    RunningTotals(CurrentPageNumber) = CurrentPageTotal + GetRunningTotal(CurrentPageNumber - 1)

    Return RunningTotals(CurrentPageNumber)

    End Function 


    13. Ok, it’s now time to add a Transfooter and Transheader.

    Enable Page Header and Page Footer in the report (click “Report->Page Header” and “Report->Page Footer”).

    14. In the Page Footer I place a text box with the following expression:

    ="Transfooter subtotal = " & Code.SetRunningTotal( Sum(ReportItems!Customer__Debit_Amount_.Value), Globals!PageNumber)


    This code actually performs the following actions:

    - calculate the sum of all “Debit Amount” values on the current page (sic)

    - adds this value to the running total, which has been already calculated for the previous page

    - returns this value as the actual running total for the current page

    15. In the Page header I place a text box with the following expression:

    ="Transheader subtotal = " & Code.GetRunningTotal(Globals!PageNumber-1)

    This code fetches the running total, calculated up to the previous page


    16. And then I set distinctive BackgroundColor and font Color just so this Transfooter and Transheader stand out in my report


    17. Now I’m almost done but I would like to not see the Transheader on the first page and not to see the Transfooter on the last page.

    So I set the following expressions for the “Visibilty->Hidden” properties of the page header:

    =IIF(Globals!PageNumber > 1, False, True)

    And for the page footer:

    =IIF(Globals!PageNumber < Globals!TotalPages, False, True)

    18. Now I’m done, I save, import into NAV and compile. After some fit and finish on the report it now looks like this when I print

    Now I’m done, I save, import into NAV and compile. After some fit and finish on the report it now looks like this when I print:



    Question: Would this also work in the example of having a list of sales order lines per sales header and the sales order lines goes to multiple pages?

    Answer: The report above is a bit simplified in order to illustrate the point. It can be easily extended to support your scenario. I.e. the key for the hash should include page number AND header no to accomplish this.

    You can download the report object here, thanks to Nickolay Belofastow.

    /Claus Lundstrøm

  • Microsoft Dynamics NAV Team Blog

    Welcome to the Dynamics NAV Team Blog


    Welcome to the Dynamics NAV team blog!! It is critically important for our team to be able to connect with our customers and partners at every opportunity that we can. We are committed to building great products to help you maximize your return on investment with the Dynamics NAV product.

    Sometime last year we passed the 1,000,000 user mark with Dynamics NAV. That is an amazing milestone and we can’t thank you enough for your support of the product and your feedback over the years. Our goal with this blog is to create another place where we can come even closer together as a community, where we can share what we are doing with the product, respond to your questions and concerns, and hopefully pull together around what we believe is our common goal.

    We have been able to get together with some of you at our Convergence Conferences over the years and I cannot describe how much value we have gotten from those experiences. Those countless discussions have resulted in a customer model for your businesses, it has resulted in over 60 personas for different roles in an organization, and it has resulted in one of the core themes of our next release and our role tailored client that we are rolling out across the Dynamics product line. The better we can understand your challenges and dreams the better we can help solve the challenges and make the dreams become a reality.

    Customers and Partners are always at the center of any decisions we make around the direction and functionality of our Product and as we planned for Dynamics NAV 5.0 we also used the customer model very actively, by relating the value of new features to the specific personas. By doing so we find that we as a team are able to more precisely understand and talk about the impact of new features and thereby make them even more relevant to the real users of NAV. Actually since the personas of the customer model all have been given “a name and face”, we today think and talk about our key personas as if they were old familiar members of our team to an extent that we probably wouldn’t be surprised if they one day appeared at our next team meeting in person and just greet them with a, - “Oh, hello Susan, how are you doing today!” (Susan is the name of the Order Processor in the customer model.)

    Today the Dynamics NAV community is incredibly global with over 40 language version and customers in well over 100 countries so far. This diversity provides us tremendous advantages in that we can take our learning from around the world and bring it to the rest of the world. But also means we need to have a deep understanding of what is most important for you to succeed in your local market whether you are a customer using the product, a partner selling and implementing the product, or an ISV building vertical functionality for specific markets.

    I could not be more excited to now be a part of this amazing NAV community. I thought it might be nice to give you some background on the leaders on my team. This way you can connect directly with them and I can show you that we have some very passionate, committed, and experienced people working hard every day to make your investment in Dynamics NAV the best investment you have ever made. This is just the tip of the iceberg and our goal with this blog is to have people from across our team of hundreds of developers, program managers, testers, product managers, user experience experts, content publishing writers, and more to engage with you on this forum.

    Dynamics NAV Leadership


    Dynamics NAV Architecture Leadership


    We have assembled a leadership team with decades of experience in the software industry, and also decades of experience with the Dynamics NAV product, and we are all committed along with the rest of the fantastic Dynamics NAV team to creating the best possible business solution for all of you.

    Welcome again to the Dynamics NAV team blog, this place will be become better and better if we all use it to share and come together. Thanks in advance for making this a great place to come.

    Darren Laybourn
    General Manager
    Dynamics NAV and Mobility

  • Microsoft Dynamics NAV Team Blog

    How to run 2 RTC on the same pc and connect it to different db (how to run pages/reports from diff db)


    Multiple RTC:
    We know that Dynamics NAV classic client has very nice feature: we can start it with option ID=<zup file name>. In that way we can have many NAV shortcuts which open different db/companies.
    However Role Tailored Client looks like only one shortcut in menu and always starts the same client connected to "last server, last db, last company".

    But we can create shortcuts for every needed connection in similar way as in CC, just we need to use option: settings:<clientusersettings.config file>.
    For example i want to have shortcut which always opens W1 db on server "a1", service "NAV W1", using port 7048 (not standard port). Then:

    • I search for default "clientusersettings.config" in default folder (usually it is C:\Users\...AppData\Local\Microsoft\Microsoft NAV\).
    • Copy it to somewhere - for example to NAV RTC folder and rename to for example "w1.config".  
    • Modify settings file:
      • <add key="Server" value="a1" /> 
      • <add key="ServerInstance" value="NAV W1" />
      • <add key="ServerPort" value="7048" />
    • Create shortcut: "C:\Program Files\<path to RTC>\Microsoft.Dynamics.Nav.Client.exe" -settings:"C:\Program Files\<path to RTC>\W1.config"

    Now when i will click on this shortcut, it will try to connect to service tier described in config file.
    And i can create as many shortcuts as i want and at the same time to have opened many RTC connected to different db.
    Before use this shortcuts i must to create service tiers, but this is not current topic problem, it is described at Freddys Blog

    How to run pages/reports from CC

    During developing pages and SSRS reports in CC objects designer, usually we want to run it. However there are few issues:
    - If we run page (nice feature in Dynamics NAV SP1), it will start last RTC session connection. I mean for example i just looked how page looks in db "w1" by run it from RTC, and now opened CC and designing page in db "UK", and, if i push run button in object designer, then NAV will open RTC and run page from company "w1" (but I'm expecting "UK"). This is because NAV CC has no information about "service tier" and just starts last RTC session.
    - There are no possibilities "by default" to run RTC report from CC.

    With my friends help i created little trick and can run page/report from CC from current connected db.

    1. I created table with fields:
      1. User ID Code 20 - user id which will run page/report (for example: gediminb)
      2. RTC Client exe Text 250 - path and name to RTC client exe file (for example: C:\NAV RTC\Microsoft.Dynamics.NAV.Client.exe)
      3. Server Name Text 30 - NAV server name (where is service tier installed) (For example "DBServer")
      4. NAV Server Name Text 250 - NAV service tier name (for example: NAV W1)
      5. Settings  path+name Text 250 - path and name of client user settings file (i described earlier) (for example: C:\NAV RTC\w1.config)
    2. I created form based on "Object" table, filtered pages and reports and under button i added code:

    Session.SETRANGE("My Session",TRUE);

    WITH DevUserSetup DO BEGIN
      GET(LoginMgt.ShortUserID(Session."User ID"));

      TESTFIELD("Server Name");
      TESTFIELD("RTC Client exe");
      TESTFIELD("NAV Server Name");

     IF DELCHR(DevUserSetup."Settings  path+name")=''
        THEN txtSettings := ''
        txtSettings:='-settings:"'+DevUserSetup."Settings  path+name"+'"';

      ShellString := '"' + "RTC Client exe" + '"';

    IF Rec.Type=Rec.Type::Page THEN
      ShellParam := '"DynamicsNAV://' + "Server Name" + '/' +
                    "NAV Server Name" + '/' + COMPANYNAME + '/' +
                    'RunPage?Page=' + FORMAT(Rec.ID) + '" '+txtSettings;
    IF Rec.Type=Type::Report THEN
      ShellParam := '"DynamicsNAV://' + "Server Name" + '/' +
                    "NAV Server Name" + '/' + COMPANYNAME + '/' +
                    'RunReport?Report=' + FORMAT(Rec.ID) + '" '+txtSettings;




    Here "DevUserSetup" is variable type rec and point to my previous created table.

    So what does this code when i push button when cursor is on report 21? It creates string like: "c:\NAV RTC\Microsoft.Dynamics.NAV.Client.exe" "DynamicsNAV://DBserver/NAV W1/CRONUS International Ltd./RunReport?Report=21" -settings:"c:\NAV RTC\W1.config" and run it from SHELL.
    This will run RTC and opens report i want to see with data i want to look.
    The same is if i push button when cursor is on page.

    That's all
    Special thanks to Martin Jordt Hansen

    Gedas Busniauskas (gediminb)
    Microsoft Customer Service and Support (CSS) EMEA

Page 1 of 41 (615 items) 12345»