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 :
Microsoft Dynamics AX (Archived)

Dynamics AX Query Range

(0) ShareShare
ReportReport
Posted on by

Hi,

   Dynamics AX 2009, I want to add a range to a date field (Field name - EndDate) in Query such that it fetches only those records where that 'EndDate' falls in the current month. I don't think I can do that in the AOT object as such, but should be able to code it in the init() method.

The function MthOfYr(systemdateget()) actually gets me close to what I want. I get the numeric value of the month, but still not clear on how do I actually put it in setting the range. Can someone plz help?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Oleg Abapolov Profile Picture
    39 on at

    I believe this can help

    queryRange(dateStartMth(currentDate), dateEndMth(currentDate));

  • Saurabh_star Profile Picture
    on at

    I was actually expecting a logic such as MthOfYr(endDate) == MthOfYr(systemdateget())

    but If thts difficult, the one you mentioned is a fair option as well. Can that be put in the properties window of the range or have to write it in method?

  • Suggested answer
    Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    In code, you could use dateStartMth() and dateEndMth() together with SysQuery::queryRange().

    But there is an easier way that can be use directly in AOT: monthRange(). Please note that functions from SysQueryRangeUtil class must be enclosed in brackets when used in query ranges - e.g. (monthRange()).

  • Suggested answer
    Dick Wenning Profile Picture
    8,705 Moderator on at

    look at class SysQueryRangeUtil

    public static str monthRange(int relativeMonthsFrom = 0, int relativeMonthsTo = 0)

    {

       utcdatetime     currentDateTime;

       utcdatetime     monthStartDate;

       int             dayValue;

       currentDateTime = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(), DateTimeUtil::getUserPreferredTimeZone());

       dayValue = DateTimeUtil::day(currentDateTime) - 1;

       monthStartDate = DateTimeUtil::addDays(currentDateTime, -dayValue);

       return SysQueryRangeUtil::dateRange(DateTimeUtil::date(DateTimeUtil::addMonths(monthStartDate,relativeMonthsFrom)),

                                               DateTimeUtil::date(DateTimeUtil::addDays(DateTimeUtil::addMonths(monthStartDate,relativeMonthsTo +1), -1)));

    }

    in your aot Range (monthRange(-1,0))

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Saurabh,

    It can't be put in properties window

    above solution suggested by Oleg, can be used using Query object in init() method

    I think solution provided by Oleg is the best solution you have for your requirement

    Please verify and let us know if you have more details..

  • Saurabh_star Profile Picture
    on at

    Thanks Oleg,

      it worked absolutely fine. It was short and simple.. :)

  • Saurabh_star Profile Picture
    on at

    Yes Nitesh....you are right. It worked well.

    Thanks Dick and Martin as well for your comments.

  • Oleg Abapolov Profile Picture
    39 on at

    The solution suggested by Martin Dráb and Dick Wenning works perfectly:

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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans