Saturday, September 29, 2012

"The date is not valid" in Navision 2009 SP1 or R2

Today I got a request in which the client was getting "the date is not valid" error when they are trying to authorize credit card using Navision Webservice. They were using chargelogic add-on and exposed a codeunit in which it has functions to authorize credit card.


When I first saw that error my initial thought was it is something related to settings in customsettings. config file. So we changed "WebServicesDefaultTimeZone” setting to use "Server Time Zone". But unfortunately that did not fix the issue and we kept getting the same error. Then I used my debugging skills to find the part of code where the error was happening. Once I debugged it I found that they have some customizations to improve performance in which one of them was to use single instance codeunit to get data from setup tables. Instead of using normal statement table.GET statement they stored all these get statements in separate functions in a single instance codeunit and they called this codeunit whenever they wanted to use GET statement for setup tables.



In all those functions they have a statement where they will execute GET statement if the previous GET statement is past one hour and they have a line of code like this to check

IF (CURRENTDATETIME - DateSetupRead) >840000 THEN
    GLSetup.GET;

In the above statement DateSetupRead is undefined datetime i.e. 0DT for the first time it is called and which works fine in CLASSIC but if you try to execute above statement in RTC you get the above error, i.e. "The date is not valid"

To resolve this I have added this statement

           IF ISSERVICETIER THEN BEGIN
              IF FORMAT(DateSetupRead) ='' THEN
                 DateSetupRead := CREATEDATETIME(010101D,150000T);
          END;

and this resolved our issue.

I hope this post will help someone who might face the same issue




Share:

0 comments: