Date and Time Overlapping check - Axapta
This is a discussion on Date and Time Overlapping check - Axapta ; Hi All,
I have written a method to find date and time overlap check in a table.
(Similar to Dateoverlapcheck method available in BOMVersion).
The code works for almost all condition, expect for one condition.
static boolean checkDateTimeOverlap(Table1 _currVersion,
Table1
...
-
Date and Time Overlapping check
Hi All,
I have written a method to find date and time overlap check in a table.
(Similar to Dateoverlapcheck method available in BOMVersion).
The code works for almost all condition, expect for one condition.
static boolean checkDateTimeOverlap(Table1 _currVersion,
Table1
_checkAgainstVersion)
{
UTCDateTime currFromDateTime =
DateTimeUtil::newDateTime(_currVersion.FromDate,_currVersion. FromTime);
UTCDateTime currToDateTime =
DateTimeUtil::newDateTime(_currVersion.ToDate,_currVersion. ToTime);
UTCDateTime checkAgainstFromDateTime =
DateTimeUtil::newDateTime(_checkAgainstVersion.FromDate,_checkAgainstVersion.
FromTime);
UTCDateTime checkAgainstToDateTime =
DateTimeUtil::newDateTime(_checkAgainstVersion.ToDate,_checkAgainstVersion.
ToTime);
;
if (currFromDateTime <= checkAgainstToDateTime && currFromDateTime >=
checkAgainstFromDateTime)
return checkFailed(strfmt("The specified date and time interval
overlaps with the date and time interval of another record "));
else
if (currFromDateTime <= checkAgainstToDateTime)
if(!(currFromDateTime < checkAgainstFromDateTime &&
currToDateTime < checkAgainstFromDateTime))
return checkFailed(strfmt("The specified date and time
interval overlaps with the date and time interval of another record "));
return true;
}
The above code works for almost all condition, expect for one condition. For
example say I have created 2 records
Record 1:
Fromdate : 10-Aug-2008
FromTime: 9 AM
ToDate : 12-Aug-2008
ToTime: 1 PM
Record 2:
Fromdate : 10-Aug-2008
FromTime: 9 AM
ToDate :
ToTime: 1 PM
In record 2. I am keeping the toDate open. As per the logic, the system
should not allow as it is overlapping. But my code doesn’t track that.
Please help me.
Thanks.
--
Venkatesh
-
RE: Date and Time Overlapping check
Hi Venkatesh,
How about running a check to see if checkAgainstToDateTime is empty. If so
then return a checkFailed...
Something like:
if( checkAgainstToDateTime == NULL ) // might have to turn date to a string
before this
{
return checkFailed(strfmt("ToDate is empty, cannot run check")
}
" if (currFromDateTime <= checkAgainstToDateTime && currFromDateTime >=
checkAgainstFromDateTime)
return checkFailed(strfmt("The specified date and time interval
overlaps with the date and time interval of another record ")); "
I believe this check will never return because checkAgainstToDateTime can
not be compared with currFromDateTime if it is not existent.
I would just run another conditional statement that checks for empty dates.
I hope this helps... (rather new with AX, but trying to help)...
-SysProg
I would just throw
"Venkatesh" wrote:
> Hi All,
>
> I have written a method to find date and time overlap check in a table.
> (Similar to Dateoverlapcheck method available in BOMVersion).
>
> The code works for almost all condition, expect for one condition.
>
> static boolean checkDateTimeOverlap(Table1 _currVersion,
> Table1
> _checkAgainstVersion)
> {
> UTCDateTime currFromDateTime =
> DateTimeUtil::newDateTime(_currVersion.FromDate,_currVersion. FromTime);
> UTCDateTime currToDateTime =
> DateTimeUtil::newDateTime(_currVersion.ToDate,_currVersion. ToTime);
> UTCDateTime checkAgainstFromDateTime =
> DateTimeUtil::newDateTime(_checkAgainstVersion.FromDate,_checkAgainstVersion.
> FromTime);
> UTCDateTime checkAgainstToDateTime =
> DateTimeUtil::newDateTime(_checkAgainstVersion.ToDate,_checkAgainstVersion.
> ToTime);
>
>
> ;
>
> if (currFromDateTime <= checkAgainstToDateTime && currFromDateTime >=
> checkAgainstFromDateTime)
> return checkFailed(strfmt("The specified date and time interval
> overlaps with the date and time interval of another record "));
> else
> if (currFromDateTime <= checkAgainstToDateTime)
> if(!(currFromDateTime < checkAgainstFromDateTime &&
> currToDateTime < checkAgainstFromDateTime))
> return checkFailed(strfmt("The specified date and time
> interval overlaps with the date and time interval of another record "));
>
> return true;
> }
>
> The above code works for almost all condition, expect for one condition. For
> example say I have created 2 records
>
> Record 1:
> Fromdate : 10-Aug-2008
> FromTime: 9 AM
> ToDate : 12-Aug-2008
> ToTime: 1 PM
>
> Record 2:
>
> Fromdate : 10-Aug-2008
> FromTime: 9 AM
> ToDate :
> ToTime: 1 PM
>
> In record 2. I am keeping the toDate open. As per the logic, the system
> should not allow as it is overlapping. But my code doesn’t track that.
>
>
> Please help me.
>
> Thanks.
>
>
>
>
> --
> Venkatesh