NEWS by Erich Stähli |
Dynamics 365 Business Central on-premise - 1st SwissSalary version available
SwissSalary is ready for Dynamics 365 Business Central on-premise
Full story
NEWS by Erich Stähli |
IncaMail - Version 4.6
IncaMail has released the new version 4.6
Full story
NEWS by Erich Stähli |
Dynamics NAV 2018 | SwissSalary NAV is ready
The SwissSalary NAV objects for Dynamics NAV 2018 are available.
Full story
NEWS by Erich Stähli |
SwissSalary Hotfix 5052.002 available
Hotfix for employers with Tax at source employees in the canton GE
Full story
NEWS by Erich Stähli |
Are you ready for the first salary payment in January 2018?
In the next few days, you will make the first salary payment for January 2018. Did you adjust the percentages 2018 for the following social insurance?
Full story
NEWS by Erich Stähli |
ISO 20022 | pain.001 | new interface for salary payment
SwissSalary ist ready for the new payment standard ISO 20022 (pain.001).
Full story
NEWS by Erich Stähli |
The Income Tax Tariff for 2017 are available!
Please note any changes in the next few weeks on our homepage.
Full story
NEWS by Erich Stähli |
SwissSalary Ltd. in President's Club 2016 for Microsoft Dynamics
In 2016, we are again in the top 5% of the worldwide Microsoft Dynamics Partner! We are very pleased that we were elected to the President's Club for Microsoft Dynamics 2014 and also 2016.
Full story
NEWS by Erich Stähli |
Manual for Year-end and ELM processing | ELM-FAQ
The ELM manual ist still under revision, but may be used for the installation and transmission
Full story
NEWS by Michela De Feo |
SwissSalary is certified for Microsoft Dynamics NAV 2016
CfMD-certification (Certified for Microsoft Dynamics) successfully completed for SwissSalary NAV 2016
Full story
NEWS by Erich Stähli |
UPDATED: Income Tax Tariff 2015 are available
The Income Tax Tariff for 2015 are available! Please note any changes in the next few weeks on our homepage.
Full story
NEWS by Erich Stähli |
Family Allowances and Funds 2015 | available
There are several adjustments to family allowances and the cantonal FAK-employer contributions. In the secure customer-/ partner area you will find all documents.
Full story
NEWS by Stephan Grossenbacher |
Electronic transfer of Income Tax data exclusively with ELM
Income Tax transmission only possible with ELM, ISEL is no longer supported.
Full story

Tech

30 posts

Last post : 8/10/2018

NAV 2013 uses Unicode internally - but what does this mean for us developers?

May 22, 2014, 15:27 PM by Yanik Fahrni

The newest version of Microsoft Dynamics NAV 2013 supports and uses Unicode internally. But what does this mean for our daily live? In this article I want to share with you our experiences and pitfalls when developing SwissSalary for NAV 2013.

Unicode in general

Unicode is the mainly standard today for seamless support for all possible and impossible characters on this planet. From arabic letters to chinese to cidllic to western, unicode eats everything without complaining. So if you need a report containig arabic and japanese characters, unicode is what you want. But of course it is also very usefull for databases. If a database collection is unicode, it supports different languages in the same database. This was not possible before unicode. 

Unicode in NAV 2013

In versions before NAV 2013, the internal encoding was ASCII - a very limited character set, especially for non-western characters. With NAV 2013, the internal encoding is Unicode. This means, if NAV reads a record from the database into the memory, it is stored as Unicode in the memory. This is very important to know!

So, if we use a string value from the memory in an way the encoding matters, we must be aware of the fact that it is Unicode, not ASCII anymore.

Pitfalls

If you have this Code:

MyChar := 'ü';
MyInteger := MyChar; // gets the integer value of the character
MESSAGE(FORMAT(MyInteger));

In Versions prior NAV 2013, you got the Number xxx as the result. This was the ASCII value for the character 'ü'.

In NAV 2013, the same code gives you the number yyy as a result. This is the Unicode value for the letter 'ü'.

In SwissSalary, we need to create a lot of different import/export files with ANSI or UTF8 encoding. We had convertion functions like this:

IntegerValue := InChar;

CASE IntegerValue OF
  255: ConvertedChar := 134;
  256...
END;

EXIT(ConvertedChar);

(Of course, there where COM automations for convertion available before, but we avoided as mutch external components as possible to provide a painless installation of SwissSalary.)

Because NAV 2013 now returns the Unicode Integer Value (and not the ASCII Integer value like in previous versions) our conversion functions do not work anymore: The convertions will be wrong, if the character is converterted at all.

First, we tried to rewrite the function to support the new Unicode values. But hey, Unicode is not limited at all in terms of maximal numbers of characters, and it get's updated every month or two. Do we want to update this for the rest of our developer live by hand? Certainly not.

As NAV2013  supports the .NET framework for all avalable clients (at least server side) we can now take advantage of the convertion functionalities .NET provides. And based on the fact that NAV 2013 is built completly on the .NET framework, we can be shure that it is available and can use ist without worries.

The solution

With the .NET component StreamReader we now can convert Unicode much simpler in NAV 2013. The following code shows how to import a ANSI encode file in NAV:

You can download the demo here.

Conclusion

Unicode in NAV 2013 is a good thing for sure and long overdue. But you have to know what changed inside NAV to get your functions work, escpecially when writing/reading files or streams.

Btw: In XMLPorts, you can define the Encoding in the Properties, so you don't have to use a convertion function.

<screenshot>

And because ASCII and UTF8 are subsets of Unicode, we don't even need to convert those anymore when importing a file!

http://cagle.com/working/080213/singer.gif

http://upload.wikimedia.org/wikipedia/commons/thumb/a/ab/Unicode_logo.svg/220px-Unicode_logo.svg.png