Working with dates in NAV

To work following the standards avoids future issues.

In this post I’d like to suggest a way to convert dates in NAV.

Working with dates in NAV

A date in your system can have different formats depending on the preferences of your country and language.

You can come across different errors, for example Server and Client with different settings or ambiguous date because valid between two different formats (e.g. 05/04/2015 that could be DD/MM/YYYY or MM/DD/YYYY)

To avoid this confusion there is an International Standard that is the standard XML format that returns the date in the following format

YYYY-MM-DD

In NAV you can use the FORMAT Function (Code, Text) with the following declaration:

String := FORMAT(Value[, Length][, FormatStr/FormatNumber])

and using the FormatStr = 9 to return a string in XML format

FORMAT(varDate,0,9);

Note: Leaving the Length = 0 then the entire value is returned.

This example requires that you create the following variables:

Name DataType Subtype
varDate Date

Example:

varDate := DMY2DATE(5,4,2015);
MESSAGE(FORMAT(varDate,0,9));

It will return
Working with dates in NAV

How to convert from a string in XML format back to a field or variable of type Date?

To convert a string in a date in NAV we need to call the EVALUATE Function with the following declaration:

[Ok :=] EVALUATE(Variable, String[, Number])

It’s interesting that also in this function we can use Number = 9 to set that the string expected will be in XML format.

Using the standard XML format you will work in accordance to the standards and the configuration of your Server or Client, language or preference in your system will not affect your work and each date will be converted always in the same manner.

Remind that you can use the same functions and logic working with DateTime.

Did my post help you? Leave a reply.

HOW TO load xml from a file in C/AL

In the following example we are going to: open a file, create an InStream object, create an XmlDocument using the DotNet component and load the xml from the InStream.

This example requires that you create the following variables:

Name DataType Subtype
TestFile File
Istream InStream
XmlDoc DotNet
System.Xml.XmlDocument.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

HOW TO load xml from a file in C/AL?

TestFile.OPEN('C:\TestFolder\TestFile.xml');
TestFile.CREATEINSTREAM(Istream);

XmlDoc := XmlDoc.XmlDocument();
XmlDoc.Load(Istream);

Did my HOW TO help you? Leave a reply.

Tips & Tricks – create sitemap automatically

To create automatically an updated site map (or sitemap) of your website I suggest you to use the

Sitemaps Generator

XML Sitemaps Generator | XML-Sitemas.com
Create your Google Sitemap Online – XML Sitemaps Generator

Services:

  • Free Online Generator (Maximum 500 pages)
  • Unlimited Generator (No limits)
  • Online PRO Service

To use the online Free Service, you need to enter some simple details:

  1. the full http address for your site
  2. change frequency
  3. last modification (if you don’t know use “Use server’s response”)
  4. priority (if you don’t know use “Automatically Calculated Priority”)

Then Start. Maximum 500 pages will be indexed in sitemap.

With the Free service, after process, you can download the following formats:

  • un-compressed XML (.xml)
  • compressed XML (.xml.gz)
  • HTML (.html)
  • in Text Format (urllist.txt)
  • ROR (ror.xml)

With the Payment Services you can generate any kind of Sitemap you require:

  • XML
  • HTML
  • Images
  • Video
  • News
  • Text formatted
  • Mobile

Do you think that my Tip & Trick is useful? Leave a reply.

HOW TO validate XML from XSD on Microsoft Windows

Download, install and launch XML Notepad 2007.
Open your XML file (File -> Open) and select Schemas… in the View menu.
Press the […] button to select the XSL file.

Now you can read validation errors into the Error List bottom of the window.

Did my HOW TO help you?

mendelson AS2 solution – “@MessageHTTPUploader.performUpload: [SocketException]: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)”

@MessageHTTPUploader.performUpload: [SocketException]: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)

You must insert correct keystore password into
File -> Preferences -> Security -> Keystore password (https send)
then restart the program.

Did my solution solve your problem?