Skip to main content

Notifications

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

     }

 }

  • Ratish Shetty Profile Picture
    Ratish Shetty 5 on at
    RE: Accurate Accounting Date related code generates inaccurate results

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

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,160 Super User 2025 Season 1 on at
    RE: Accurate Accounting Date related code generates inaccurate results

    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
    Ratish Shetty 5 on at
    RE: Accurate Accounting Date related code generates inaccurate results

    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
    André Arnaud de Cal... 292,160 Super User 2025 Season 1 on at
    RE: Accurate Accounting Date related code generates inaccurate results

    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?

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,160 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans