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

Notifications

Announcements

Community site session details

Community site session details

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

QueryBuildRange to check start and end date

(2) ShareShare
ReportReport
Posted on by 608
Hello,
I have a record with ActiveFrom and ActiveTo dates.
I'm writing a query using the query object but I'm stuck. How do I use a BuildQueryRange to check if the ActiveFrom is less than or equal to today, and of course if ActiveTo is greater than or equal to today. I see a lot of reference to using SysQuery::Range() but I'm not sure how that would work for my scenario. 
I have the same question (0)
  • Martin Dráb Profile Picture
    238,097 Most Valuable Professional on at
    Is it a date-effecive table? If you don't know, check its Valid Time State Field Type property.
  • Suggested answer
    Martin Dráb Profile Picture
    238,097 Most Valuable Professional on at
    Using SysQuery::range() or queryRange() (which is a shorter way of the same) is a good idea. One of the operands is clear - you'll use the current date. Use null for the other, which won't set any boundary there (therefore it'll be some like from:today to:unlimited). Here is some code:
    date today = DateTimeUtil::getToday(DateTimeUtil::getUserPreferredTimeZone());
    ds.addRange(fieldNum(DimensionAttrValueLedgerOverride, ActiveFrom)).value(queryRange(null, today));
    ds.addRange(fieldNum(DimensionAttrValueLedgerOverride, ActiveTo)).value(queryRange(today, null));
  • Verified answer
    Martin Dráb Profile Picture
    238,097 Most Valuable Professional on at
    Don't you want to say that "ActiveTo is either 1900-01-01 or greater than or equal to today" instead of "ActiveTo is not this 1900-01-01 date and ActiveTo is greater than or equal to today"?
     
    All values greater than today are surely not equal to 1900-01-01. Accepting 1900-01-01 (= no date) means that you understand it as no limit on ActiveTo.
     
    If you agree with my definition, then you can simple add one more range:
    ds.addRange(fieldNum(DimensionAttrValueLedgerOverride, ActiveTo)).value(queryValue(dateNull()));

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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 679 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 429 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 264 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans