web
You’re offline. This is a read only version of the page.
close
Skip to main content
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 548
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)
  • Verified answer
    Martin Dráb Profile Picture
    236,017 Most Valuable Professional on at
    QueryBuildRange to check start and end date
    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()));
  • Suggested answer
    Martin Dráb Profile Picture
    236,017 Most Valuable Professional on at
    QueryBuildRange to check start and end date
    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));
  • Martin Dráb Profile Picture
    236,017 Most Valuable Professional on at
    QueryBuildRange to check start and end date
    Is it a date-effecive table? If you don't know, check its Valid Time State Field Type property.

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

Responsible AI policies

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

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 814 User Group Leader

#2
André Arnaud de Calavon Profile Picture

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

#3
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 622

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans