Rounding DateTime as part of Web Service call

nick_robbo
Member Posts: 49
Hi,
As part of our solution, we have an application which sends Web Service calls to NAV in order to Clock In/Clock Out Employees.
When an entry is made in the table, we validate the "Event Time" and then calculate an "Amended Time" in the table trigger.
This second time is in essence a rounded time, taking into account grace periods for lateness/overtime.
For example, if I am meant to start work at 7AM, and clock in at 7:04AM, the system will calculate the "Amended Time" as 7AM.
We are seeing some instances, where this is incorrectly being rounded to 7:30AM.
Yet, if I re-validate the field "Event Time" without changing the value...it calculates correctly.
This happens for every example we get.
I have run some scripts to insert say 100 rows into the table (from a codeunit), and error if the time is incorrectly rounded. Which frustratingly passes every time.
I guess my question is, how could this be happening....the value of the field runs through the same logic, with the same value...and comes out with different answers.
Has anyone encountered issues like this before, in relation to Web-Service calls?
As part of our solution, we have an application which sends Web Service calls to NAV in order to Clock In/Clock Out Employees.
When an entry is made in the table, we validate the "Event Time" and then calculate an "Amended Time" in the table trigger.
This second time is in essence a rounded time, taking into account grace periods for lateness/overtime.
For example, if I am meant to start work at 7AM, and clock in at 7:04AM, the system will calculate the "Amended Time" as 7AM.
We are seeing some instances, where this is incorrectly being rounded to 7:30AM.
Yet, if I re-validate the field "Event Time" without changing the value...it calculates correctly.
This happens for every example we get.
I have run some scripts to insert say 100 rows into the table (from a codeunit), and error if the time is incorrectly rounded. Which frustratingly passes every time.
I guess my question is, how could this be happening....the value of the field runs through the same logic, with the same value...and comes out with different answers.
Has anyone encountered issues like this before, in relation to Web-Service calls?
0
Best Answer
-
I have found the issue,
The XML was passed correctly to the Web Service, but the issue is this lineExpectedClockInDateTime := CREATEDATETIME(DT2DATE(EventDateTime), ExpectedClockInTime);
CREATEDATETIME is adding an hour on the to time which we specify in the variable ExpectedClockInTime.
So this needs to be converted to UTC time.0
Answers
-
Here is the function which is called...... which is passed the following parameters "EmployeeNo, EventDateTime) Returns - DateTime
GracePeriod := 240000; // 4 mins RoundingTimePeriod := 1800000; // 30 mins EventDateTime := ROUNDDATETIME(EventDateTime, 60000); // round to minute ExpectedClockInTime := GetExpectedClockInTime(EmployeeNo, EventDateTime); IF ExpectedClockInTime = 0T THEN EXIT(EventDateTime); // if no expected, exit without rounding ExpectedClockInDateTime := CREATEDATETIME(DT2DATE(EventDateTime), ExpectedClockInTime); IF CheckTimeWithinGracePeriod(GracePeriod, EventDateTime, ExpectedClockInDateTime) THEN EXIT(ExpectedClockInDateTime); IF EventDateTime < ExpectedClockInDateTime THEN EXIT(GetAmendedTimeForEarlyClockIn(EventDateTime, ExpectedClockInDateTime, GracePeriod, RoundingTimePeriod)) ELSE IF EventDateTime > ExpectedClockInDateTime THEN EXIT(GetAmendedTimeForLateClockIn(EventDateTime, ExpectedClockInDateTime, GracePeriod, RoundingTimePeriod)) ELSE EXIT(EventDateTime);
The examples which are causing us a problem should exit at this line -IF CheckTimeWithinGracePeriod(GracePeriod, EventDateTime, ExpectedClockInDateTime) THEN EXIT(ExpectedClockInDateTime);
Which is why it is so strange that when I re-validate the field, which calls this code...it does exit correctly at this point.0 -
I have found the issue,
The XML was passed correctly to the Web Service, but the issue is this lineExpectedClockInDateTime := CREATEDATETIME(DT2DATE(EventDateTime), ExpectedClockInTime);
CREATEDATETIME is adding an hour on the to time which we specify in the variable ExpectedClockInTime.
So this needs to be converted to UTC time.0 -
Have a look at the settings on your service tier. There is a setting called 'Service Default Time Zone'. Depending on the value this can adjust times in web service calls depending on timezones. Might not be your issue but worth checking.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions