web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Accurate Accounting Date related code generates inaccurate results

(0) ShareShare
ReportReport
Posted on by 5

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);

     }

 }

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    303,338 Super User 2026 Season 1 on at

    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?

  • Ratish Shetty Profile Picture
    5 on at

    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”.

    4784.MicrosoftTeams_2D00_image-_2800_11_2900_.png

    Issue:

    1. One custom view has accounting date as Range. The range is getting value from a Custom class method but the class method is returning a wrong value. However if we just add a blank space in the method and re compile the code, it returns the correct value. I don't have a clue about this weird behavior.
    2. Example:
      1. We created one runnable view to call that class method. If the current date is 9th May 2023, it should return the value as <”1/5/2023”, instead it returns <”1/3/2023”.
      2. This is happening in all the environments including PROD.

    The view used was below whose accounting range is calling the class method MTVoyageClass::lessthanLastMonth()

    6738683.png

    The class method is using standard X++ functions:

  • André Arnaud de Calavon Profile Picture
    303,338 Super User 2026 Season 1 on at

    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.

  • Ratish Shetty Profile Picture
    5 on at

    It seem to be not working. I'll get the error details posted shortly.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 509 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 375

#3
Adis Profile Picture

Adis 268 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans