Hello team!

I've prepared this blog post because of only few of people which I asked known about this feature, and I decided that "world should know about it". This example actual for both languages - AL and C/AL.

Most of us use data import from XML files. Directly or from API response messages.

And I bet, that most of you faced with a problem of converting XML values to NAV data types.

For example - XML date, which is YYYY-MM-DD. If you try to use EVALUATE(NavDate, XMLDate) - you'll get an error.

I saw different convert functions like this:

NavDate := 
  DMY2DATE(
    COPYSTR(XmlDate,7,2),
    COPYSTR(XmlDate,5,2),
    COPYSTR(XmlDate,1,4));


It's working but it's not a clean code.

It's not obvious, but EVALUATE function has 3rd non mandatory parameter:

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

And we see that it could have the only value:

Number
Type: Integer

This optional value can be used when exporting data with an XMLport. 
The only valid value is 9, which indicates that the data must be converted from XML format to C/SIDE format.


So we could just use this, and get the needed result:

EVALUATE(NavDate, XMLDate, 9);


The same way we could use with decimal values if your country has decimal places delimeter not equal to dot "." In Russia we use comma "," delimeter and EVALUATE(NavDecimal, XmlDecimal) - also throws an error. I saw next code:

EVALUATE(NavDecimal, CONVERTSTR(XmlDecimal, '.', ','));


But the correct way is:

EVALUATE(NavDecimal, XmlDecimal, 9);


Hope, this post was helpful for you!