Friday, August 5, 2016

Using With Statement in C/AL code | Make Code Simple Series

How to write lesser code in NAV...!!??!!

There is always a better way. I am fortifying my Programming skills everyday with some customized code. I like to make coding life interesting so i keep on making small changes to make life easier and programming more intelligent. 

I would like to share today about With Statement. When we work with records(except Current record 'rec'), addressing is created as record name, dot (period), and field name:

For example let say we are coding into Sales line table with 'Item' record. then we need to continuously use "Item.FieldName" and if we need to write code for ten or twenty fields or any field repeatedly then it makes no sense using Item(Dot) always. This is where we should know WITH STATEMENT. 

WITH <Record> DO
  "No." := '1234';         //Instead of Item."No."
  Description:= 'Pokemon GO Server';      //Instead of Item.Description
  "Unit Cost" := '50000.50';       //Item."Unit Cost"
//Other codes


Thursday, August 4, 2016

Installing multiple Instances/DB | Dynamics NAV | on a single Machine | For Beginners

Hello Folks,

I recently felt many of my clients(technical team) are facing problem understanding the process involved in creating multiple instances of databases. Generally in every server we have a TEST DB and a LIVE DB(there can be more depending on the nature and stage of project). Inside every DB there can be as many Company as the system can hold.

For technical personnel, the main concern is how to maintain two databases, one for testing Objects sent from the Developers and then after successful testing can be transferred to the Live DB for final level testing... Generally all the objects are kept similar between Test and Live DB(may not be the case always).

You can always find these technical details on in details but in most of the cases i have seen, users feel uncomfortable reading all those walk-through and most of them prefer either video tutorial or the blogs with images.

I am assuming Version 2016 since i'll be attaching snaps of version 2016.
Let us assume we already have LIVE DB. It has Instance Named "DynamicsNAV90", which is the default name...
The ports used by DynamicsNAV90 are:
Client Services: 7056
SOAP Services: 7057
OData Services: 7058
Management Services: 7055 

Now lets replicate the Database. We can do this from SQL Server Management Studio.
I'll not go in details since this is all normal steps...

Now lets assume we have a New Database named "Demo Database NAV (9-0)_new"...

Now lets create a New Instance from "Dynamics NAV 2016 Administration", Lets right click on Console Root/Microsoft Dynamics NAV(Local) and click on Add Instance.

It will populate a new window where we are supposed to enter the server name and different ports. Lets use different port since we don't want port conflict issue and this is the main part, since we are assigning totally different port to a new instance they will be totally independent entity and they can run independently. Lets now assign the Database we just created "Demo Database NAV (9-0)_new" to this instance(ForTestDB is our new Instance).

New Instance Name: ForTestDB
Client Services: 5060
SOAP Services: 5061
OData Services: 5062
Management Services: 5059
(you can choose any available Ports, just keep the port number together and in the same range, it helps you remember the ports)

Now lets go to Services(go to RUN(win +R) and enter Services.msc and press enter) and confirm that both the services are running(see the snapshot).

Now we are all configured. We just need to go to Development environment and check the Database information and confirm the Server Instance has a value in General section.

Now lets run RTC. First Client will run automatically since it was working before. Now let open RTC again(keep previous RTC open) in the left side we have a Down arrow icon click on it and select "Select Server". Here we will have to enter the Server Address manually. the format of Server address is :"localhost:"ClientServiceport"/InstanceName" so in my case it is "localhost"5060/ForTestDB".

Here you go, you have two NAV RTC running on the same machine. You can follow the same step to install and run as many NAV system on your machine as your system can. This also works for other versions and inter-version installation...


Monday, August 1, 2016

Export to CSV File | RTC/CLASSIC Report

Statement: Save the content of Report to CSV file in a Specific Template.
One of our client came of with a requirement to generate a 'Comma Separated Value' Format Data from a report (Bank Account - Check Details).

There are many ways to do this,  i used File Method...

For the sake of this example i am using classic Client. It works sames in RTC as well(up to NAV- 2016 Tested).

Global Variables Created

tpath  [Text-100]
tFilename 9 [Text-50]
lfi_ExportFile [File ]
ltx_Line [Text-1024]
ltx_CRLF [Text-30]
ltx_LineHead [Text-250]
lBankAccount [Integer]
lCheckLedgerEntry [Record-Check Ledger Entry]
SalesReceivablesSetup [Record-Sales & Receivables Setup]
CreateCSVfile [Boolean]
Total_Amount [Decimal]
Total_AmountVoided [Decimal]
Total_AmountPrinted [Decimal]


Bank Account - OnPreDataItem()
CurrReport.NEWPAGEPERRECORD := PrintOnlyOnePerPage;
  RecordCounter :=0;


//For New Line...
  ltx_CRLF := '';
  ltx_CRLF[1] := 13;
  ltx_CRLF[2] := 10;

//For Textmode ON

//For the Location of CSV file
    IF  SalesReceivablesSetup."Check Detail- CSV File Locatio"<>'' THEN
    tpath := SalesReceivablesSetup."Check Detail- CSV File Locatio"
     ERROR(Error Message);

 //File Name Format
    tFilename := FORMAT(tpath) + 'Check Detail-'+ FORMAT(TODAY,0,'<day,2>-<month,2>-<year,2>') +
     FORMAT(TIME, 0, '<hour,2><minute,2><second,2>') +'.' + 'csv';
    IF CreateCSVfile= TRUE THEN


Integer - OnAfterGetRecord()
IF NOT CheckLedgEntryExists THEN

//For the given format...
 ltx_Line :=  "Bank Account"."No."+ ','+'' +','+''+ ','+ '' +','  +    DELCHR(FORMAT(Total_Amount),'=',',') +','
   + DELCHR(FORMAT(Total_AmountPrinted),'=',',') +','  +DELCHR(FORMAT(Total_AmountVoided),'=',',') ;

//Every line will be copied to ltx_Line & get copied to CSV file instead of storing multiple line.

//Resetting the Total Values
Total_Amount :=0;
Total_AmountVoided := 0;
Total_AmountPrinted :=0;

Report - OnPostReport()
   IF CreateCSVfile= TRUE THEN

//Code in Report Section

Bank Account, Body (7) - OnPostSection()
IF CreateCSVfile= TRUE THEN BEGIN //Boolean in Request Page...
IF CheckLedger("Bank Account") THEN
lfi_ExportFile.WRITE("Bank Account".Name);

Check Ledger Entry, Body (2) - OnPostSection()
ltx_Line := ''+','+ FORMAT("Check Date") +','+ "Check No." + ','+
 DELCHR(Description,'=',',') + ','  + DELCHR(FORMAT(Amount),'=',',') +','
   +DELCHR(FORMAT(AmountPrinted),'=',',') +','  + DELCHR(FORMAT(AmountVoided),'=',',') +','
    + FORMAT("Entry Status") +','  +FORMAT("Original Entry Status")+
     ','  + FORMAT("Bal. Account Type") +','  +FORMAT("Bal. Account No.");


//Calculation of Total...
Total_Amount +=Amount;
Total_AmountVoided  += AmountVoided;
Total_AmountPrinted += AmountPrinted;



Note: If you want to try the same in RTC report then Use the code of Section in Dataset... It works absolutely fine in RTC as well... I tested it in 2013, 2015 and 2016 as well...


Print Preview - Content not showing | RTC Report

A Newly created report which is working fine is not showing the Line Section only for a couple of documents.
But when the same report is saved as PDF or any other format available, it is working fine.
All the codes and #dataset is correct.

For confirmation i even checked the records of the report...

It is pulling all the records and is normal. 
I rechecked all the codes but couldn't find the mistake. Then finally i started talking to some of my colleagues. One of my friend just presented a random solution and surprisingly it worked. This is the reason i am writing this blog. I cannot explain why it happens but it works...

The problem was big but the solution was just a report property option. The preview mode of the report is "Normal". In order to make this report get the Line value and preview it i changed the Preview mode to "PrintLayout" and it worked fine...

It doesn't makes enough sense why the same report was working fine for other documents and not for some of the documents(all the Documents are of almost similar line records).  

Hopefully someone will find this Blog helpful. I would be happy if i can save someone time with this solution. 

Thank you.

Friday, July 1, 2016

Confirm dialog box to confirm the process flow | NAV

Dialog boxes can be used in the place of "Message"in Dynamics NAV. It gives the option to route through if else condition with better documented options. The CONFIRM Dialog box are generally used in the same way as the MESSAGE function to display a message. However, unlike the MESSAGE function, the CONFIRM function has a required return value.

It also gives us option to handle the continuous process which are dependent and needs series of input (Confirmation) from the user. Please refer the image below.

In this Example i have used the series of Confirm dialog box to achieve a goal to retain the Sales line record. The Message should be informative enough for the user to understand the process and select the right choice. This is very friendly if used properly. 

The CONFIRM function has the following syntax.

Confirmed := CONFIRM(Message,[Value],'.');



Confirmed := TRUE
Confirmed := CONFIRM(Text001,FALSE,'.');
IF Confirmed THEN
//If Condition
//Else Condition
//Confirmed----> Boolean
//Message[Text001]---->Message for Dialog Box. Eg: Do you want to do ____


Code Screenshot:


Thursday, June 30, 2016

Dynamic Text Size and Color in RTC Report | NAV

Never say no when a client asks for something, even if it is the moon. You can always try, and anyhow there is plenty of time afterwards to explain that it was not possible. -Richard M. Nixon

The requirement was for the Report section in Microsoft Dynamics NAV 2016. Some of the contents of the report are to be adjusted into given textbox. The text size was supposed to vary and fit into the given text area. 
For the Example Purpose i have taken Sales Invoice and Ship to Name as a Field. It can be achieved in any Report.

TEST CASE I: Text length is small - So It can keep its Original Size [14 Pt]

TEST CASE II : Text length is Larder to fit in the area with same Font so it was adjusted to [10]

Note: For the Simplicity i have kept it just to two condition. 14Pt or 10Pt

Its as simple as IF/Else Condition in CAL Code. 


Code Syntax:

//Using IIf Condition
IIf(Len(Variable_Value) <= Lenght,“True_Value Pt”,“False_Value Pt”)



//Using IIF Condition for Size
=IIf(Len(Code.GetData(11,1)) <= 10, “pt”, “16pt”)

Alternative: =IIf(Len(Field!DatasetVar.Value) <= 10, “pt”, “16pt”)

//Using Switch Case for Size

=Switch(Len(Code.GetData(11,1)) <= 10, “14pt”, 

Len(Code.GetData(11,1)) >=11 AND Len(Code.GetData(11,1))<=20 , "10pt", Len(Code.GetData(11,1)) >20 , "5pt")

//Using Switch Case for Color
=Switch(Len(Code.GetData(11,1) <= 5, "Green", 

Code.GetData(11,1) >=10 AND Code.GetData(11,1)<=15 , "Amber", Code.GetData(11,1) >15 , "Red")


Note: We can use the Same type of Code for Color and other related property of Text. 

This small code trick turned out Quite handy to impress the client.

The journey of Microsoft Dynamics NAV | PCPlus to MADEIRA | A Walkthrough

The company PC&C was founded founded by Jesper BalserPeter Bang and Torben Wind in Copenhagen, Denmark.

Figure: PCPlus (1984) - Finance, Customers, Vendors and Inventory.

1983 - The company PC&C was founded founded by Jesper Balser, Peter Bang and Torben Wind in Copenhagen, Denmark.

1984 - Launch of PCPlus in Denmark & Norway – a character-based accounting solution for SOHO (small office/home office) market.

1984 - “Beauty of Simplicity” is the first company slogan.

Figure: 1987 - Navigator 1

1987 - Launch of the first version of Navision. This first character-based version Navision was basically an upgraded version of PCPlus. But the biggest change was that it was a able to run as client/server application over a LAN, where PCPlus was a single-user system. In the beginning it was only sold in Denmark and here it was distributed by IBM to their Erhvervscenters (business centers), who was required to fulfill a long number of certifications before they where allowed to sell the product. In Denmark Navision was called Navigator or most often IBM-

Figure: International Version

1990 - Launch of Navision version 3.0. This was a big change to the previous versions, as it introduced AL (application language - very similar to C/AL) based on the Pascal development language. This allowed the user to do very advanced modifications, compared to both the previous versions (where only reports, tables and forms could be changed). In fact they where unique in the market at that time. Only a few years later Navision's biggest competitor at this time, the also Danish company Damgaard Data, introduced their XAL (extended application language).

1990 - Market expansion moves beyond Scandinavia into Germany. Spain and the United Kingdom. Here the name Navision was used for the first time. 

1993 - Navision initiates a major development effort to create a new generation of Navision solutions based on Microsoft Windows 32-bit client/server platform.

Figure: New generation of Navision solutions based on Microsoft Windows 32-bit client/server platform.

1995 - Launch of Navision Financials 1.0, an accounting solution based on Microsoft Windows 32-bit client/server platform.

1995 - Launch of Navision Financials Windows 95 version and Windows NT. 

1995 - The Navision Online User Group is started by Erik P. Ernst. 

1997 - Launch of Navision Financials with simple Contact Management / CRMfunctionality.

1998 - Launch of Navision Manufacturing.

1999 - Launch of Navision Advanced Distribution.

2000 - Navision Financials receives Microsoft Windows 2000 Professional Certification and Microsoft Windows 2000 Server Certification.

2000 - Launch of Navision Commerce Gateway – worlds first solution based on Microsofts BizTalk Server.

2000 - Launch of Navision User Portal – worlds first solution based on Microsofts Digital Dashboard

2000 - The two big competitors from Denmark Navision Software a/s and Damgaard A/S (the developers of Concorde, C4, C5, XAL and Axapta) merge under the name NavisionDamgaard A/S.

2001 - Launch of Navision Attain 3.0 which includes:
·                     Re-branding of Navision Financials 
·                     Integration of e-commerce applications, Commerce Gateway, Commerce Portal 
·                     User Portal, browser-based access 
·                     Supply chain collaboration functionality including manufacturing and distribution 
·                     Extended financial management functionality 
·                     Extended and new functionality within customer relationship management 

Figure: Navision Financials Rebranding into  Navision Attain

2001 - Navision Attain receives Designed for Microsoft XP logo Awards/Certifications

2001 - The name NavisionDamgaard A/S was changed to the more easy pronounceable Navision A/S.

2002 - It was not a big surprise when Microsoft Corporation aquires Navision A/S. Most people had seen it coming. In 2000 Microsoft had a aquired Great Plains, Navision's biggest competitor on the US market, but the rumors said that Microsoft had realized that GP was not good enough to base their whole strategy upon. Navision and Great Plains was put together in a group at Microsoft called Microsoft Business Solutions and the names changed accordingly to Microsoft Business Solutions Navision. The domain name of this website also changed from to

Figure: Microsoft Business Solution

2003 - Microsoft first starts talking about Project Green. This was an initiative to merge the platforms of Navision, Axapta, Great Plains and Solomon into one system. It was first told that the first beta would be available in Q4 2004. But so far it has not happend and in 2007 Microsoft completely stopped talking about Project Green, as the they had realized that it would be a much bigger project and it also scared of a lot of potential customers, who would not invest in a software with no future.

2005 - Microsoft Business Solutions Navision 4.0 was released.

2005 - Navision version 5.0 was announced as the new big version with a completely new user interface to be released in late 2006. 

Figure: Navision Version 5.0

2005 - Microsoft changes the names the applications from Microsoft Business Solutions to Microsoft Dynamics. At the same time the name Navision is changes to NAV (not nav but n.a.v. - with all letters pronounced). 

2006 - Microsoft announces that the new user interface will not be part of Navision 5.0, but instead it will be released 6-12 months later as Dynamics NAV 5.1.

2007 - Navision version 5.0 was released. But without the new user interface, but with many new application features such as a completely redesigned Job module. The job module had basically not changed since the release of Navision 3.01 (the character based version in 1990).

2008 - First Microsoft announced that the name of the next version of Navision would not be Navision 5.1, but Dynamics NAV 6.0. Just a few months later they changed it so that it would be Dynamics NAV 2009.

2008 - At Convergence in Copenhagen in November 2008 Dynamics NAV 2009 was finally released. Included in the new version was:

The new client is released as the RoleTailored Client and from now on the old is called the Classic client. Also introduced with NAV 2009 is the new form object called Pages and the new RoleTailored reports that you must design using the Visual Studio Report Designer. 

Figure: First Role Tailored Client

2009 - Dynamics NAV 2009 Service pack 1 was released on September 1st. Microsoft Dynamics NAV 2009 introduces a service tier and the ability to expose Codeunits and Pages as web services. The web services can be used by applications such as InfoPath or Excel to call Navision business logic via codeunits or read and update data through Page objects.

Figure: Web Client Introduced

Before NAV 2013, Microsoft Dynamics NAV gave administrators the option of using either a native database server or Microsoft SQL Server, as the DBMS. SQL Server is now the exclusive database option for NAV. Retiring the old "Native database" has given way to long awaited improvements in reducing/eliminating database locking, which can occur when hundreds or thousands of users are using the same data at once.

2013 to 2015 - the "modern" versions

One of the most successful products in Microsoft is Dynamics C5. This little hybrid of an old Danish SMB accounting system, once called Concorde (which grew into XAL and later Axapta), has been the most selling accounting system in Denmark, with more than 50% of their market. For many years Microsoft had tried to copy it's success (Navision Entrepreneur) and find out what to do about C5. 
Navision was the obvious choice. But if NAV should be a possible choice, then it needed more standard functionality. They had to match both what is in C5 and what their competitors offer in the same price range. Just lowering the price would not help, if the customers still had to buy expensive third party add-ons to get bank integration, pdf import/export etc. These add-on modules alone would cost up to 10 times more than the base license for C5.
So more standard functionality had to be build. NAV also needed to become easier to administrate, if partners should be able to handle 1000's of customers. Not to mention the well known issue of upgrading customized solutions. How to handle upgrading 1000's of customer at once?
Support for PowerShell was now also part of NAV 2013. Already with NAV 2009 it had been possible to manage NAV services in NAV 2009, but now it was also for use in other areas. With NAV 2013 "Microsoft Dynamics NAV Windows PowerShell Cmdlets" was introduced.
More PowerShell and functionality in NAV 2013 R2
On October 31st. 2013 Dynamics NAV 2013 R2 was released. The release was also a goodbye to the Development Environment (aka the classic client) as the place to handle companies and backups. From now on backups and restore was to be handled in SQL, and companies from within the Windows client. The reason was that NAV now supported multi-tenency, which allows partners (and users) to setup environments where the application (objects etc.) is separate from the data. This way each customer can have it's own database (with multiple companies), but still share the actual application with many other customers.

The first release was not the best work from Microsoft. In the beginning there where no way to copy/import-export companies, inside NAV. Except from using PowerShell, which was introduced with NAV 2013. This came to a complete surprise and resulted in a lot of complaints especially from the partners and developers. But they worked fast, and had many online "firefighting" meetings with the NAV MVP's.
The R2 release also contained an entirely new Cash Management functionality, largely improved Bank Reconciliation and standard functions to handle import of bank transactions, including SEPA support for debits and credits payments.
The initial released included the default setup to most Danish banks, so that it could be part of Dynamics C5 2014. Inside a C5 2014 is just standard NAV 2013 R2, but using different role centers turns it into a much simpler setup and UI, leaving about most of the advanced functions. But at a very low monthly price - only available as a "rentable" SPLA license.

Figure: Microsoft Dynamics NAV 2013

2014 - Microsoft Dynamics NAV 2013 R2 Upgrade Patch
Microsoft Dynamics NAV with this new patch allowed CRUD(Create- Read - Update- Delete) Application on its Database Through ODATA Web Service. It facilitated creation of more 3rd Party software over MS SQL Server Database used by NAV System. 

The product team continues to listen to the the community of both partners and customers, who for years have had one major problem with Navision. The same thing that made Navision a success, the ability to customize almost every little part of the system, also makes upgrades a very time consuming. And despite good 3rd party tools like MergeTool, then there is really no tools assisting in code upgrades. The result is that many customers never upgrades, beyond the main version they are on.
In October 2014 Dynamics NAV 2015 was released. Besides the many application improvements, then upgrades was in focus in this release. It contained new data upgrade codeunits and a new set of PowerShell applets enabling partners to automate the whole upgrade process. Including code compare and merge. There is no longer a way around learning to use PowerShell.

New capabilities in Microsoft Dynamics NAV 2015 include
·                     Tablet and touch-optimized user experience.
·                     Faster access to information that matters.
·                     Radically simplified invoice design and production.
·                     Additional optimization to deploy in the cloud on Microsoft Azure and with Office 365.
2015- Dynamics NAV 2016 - a big release
On October 5th. 2015 Dynamics NAV 2016 was released. The release had a lot of new functionality, but for the geeks and the end-users. The release introduced a new code-editor, replacing the old, which more or less was unchanged since the first Windows version of NAV was release. The new editor introduced IntelliSense similar to what was known in most other development environment, such as Visual Studio.

Figure: Mobile Client, Tablet Client, PC Client and Web Client

Figure: Customized View of Microsoft Dynamics NAV 2016

2016- What comes next after NAV 2016? Dynamics NAV "Madeira" : Currently CTP (Community Technology Preview) | Office 360 | Dynamics 360 Concept

The Beta version of Project Madeira has been released for US Partners. Every one seems confused about the future of NAV after release of this Beta CTP. Independent developers are still trying to find the ways it can be harvested for the Implementation.

Figure: The Madeira using Google Chrome

Microsoft Dynamics NAV Madeira:
·                     Further enhanced 'in' Office 365 experience
·                     Further enhanced 'on' Azure experience (ERP in the Cloud)
·                     Better developer experience
·                     More service integrations
·                     Fast set-up
·                     Easy configuration
·                     ...

Mobile first, cloud first
Microsoft Dynamics NAV 2016 is the most recent version of Dynamics NAV. Microsoft is however already developing the next version, the code name is Microsoft Dynamics NAV 'Madeira'. Read more about Microsoft Dynamics NAV

·                     Sriram Maringanti Note
·                     Dynamics User Group Post