We have created a customization within D365 Finance. We have a Data view created and underneath it, is a class method. Code mentioned below. This program should return values as <”1stMay2023” when extracted in May 2023 and then in June as <”1stJune2023” and so on. However it instead returns value as <”1st Mar 2023” which is weird. If we re-compile the code (without any changes) and re-run it, it works fine. Thereafter two-three attempts later, it again starts to throw unwarranted result as <”1st Mar 2023”.
Can someone help identify what is wrong with the code?
Is someone else also facing a similar issue in D365 Finance?
public static class MTVoyageClass
{
/// <summary>
/// Returns a string which can be used as range for Accounting date upto last month transactions.
/// </summary>
[QueryRangeFunction]
public static str lessthanLastMonth()
{
int days ;
utcdatetime currentDateTime;
currentDateTime = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(), DateTimeUtil::getUserPreferredTimeZone());
days = DateTimeUtil::day(currentDateTime)-1;
return SysQueryRangeUtil::lessThanDate(-days);
}
}
It seem to be not working. I'll get the error details posted shortly.
Hi Ratish,
I have seen issues before when having a method as range value on views. It will replace that method with a date range value when you compile it.
You can try removing this method and add the date range to this view with x++ coding during runtime.
Hi Andre,
Sure. I shall remember this next time.
SystemDateTime is returning the Date and time of the GMT as Preferred timezone is GMT Universal time.
Expectation: If the current date is 9th May 2023, this class method should return the value as <”1/5/2023” however it is returning <”1/3/2023”.
Issue:
The view used was below whose accounting range is calling the class method MTVoyageClass::lessthanLastMonth()
The class method is using standard X++ functions:
Hi Ratish,
When you paste some coding, would you mind using the rich text formatting and then choose Insert > Code to paste your coding? It will then look like this which is much easier to read.
public static class MTVoyageClass { ////// Returns a string which can be used as range for Accounting date upto last month transactions. /// [QueryRangeFunction] public static str lessthanLastMonth() { int days ; utcdatetime currentDateTime; currentDateTime = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(), DateTimeUtil::getUserPreferredTimeZone()); days = DateTimeUtil::day(currentDateTime)-1; return SysQueryRangeUtil::lessThanDate(-days); } }
The coding is using the system date. Is that intended? This is returning a session date which can be changed by a user. Have you used the debugger to find out which exact date is returned by the method DateTimeUtil::getSystemDateTime?
André Arnaud de Cal...
292,160
Super User 2025 Season 1
Martin Dráb
230,962
Most Valuable Professional
nmaenpaa
101,156