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

Filter the records in Query Range based on Date

(0) ShareShare
ReportReport
Posted on by

Hi all,


 I want to filter the record in Customer Transaction(CustTrans), the Closed date should empty OR greater than Today.
 

i am tried with


criteriaOpen = this.query().dataSourceNo(1).addRange(fieldNum(CustTrans,Closed));


criteriaOpen.value(strFmt('(%1.%2 == "") || (%1.%2 < %3)',
                        this.query().dataSourceNo(1).name(), fieldStr(CustTrans, Closed), today()));

its not working.

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    236,013 Most Valuable Professional on at
    RE: Filter the records in Query Range based on Date

    Could you please explain what you mean by this statement?

    Do you realize that "OR" is added automatically if you add multiple ranges for the same field, as I did?

  • Tony Mok Profile Picture
    577 on at
    RE: Filter the records in Query Range based on Date

    Hi Martin Dráb,

    It does not support "OR" case in your code.

  • Verified answer
    Martin Dráb Profile Picture
    236,013 Most Valuable Professional on at
    RE: Filter the records in Query Range based on Date

    I strongly recommend not using the extended query syntax if it's not necessary. It's ugly and error-prone, as you've found by yourself.

    Isn't this better?

    QueryBuildDataSource ds = this.query().dataSourceNo(1);
    
    ds.addRange(fieldNum(CustTrans, Closed)).value(queryValue(dateNull());
    ds.addRange(fieldNum(CustTrans, Closed)).value(queryRange(today()+1, dateMax()));
  • Suggested answer
    Iulian Cordobin Profile Picture
    8,201 on at
    RE: Filter the records in Query Range based on Date in Ax 2012

    Try like this:

    criteriaOpen.value(strFmt('(%1.%2 == %4) || (%1.%2 < %3)',

                           this.query().dataSourceNo(1).name(), fieldStr(CustTrans, Closed), date2StrXpp(today()), date2StrXpp(datenull())));

  • Sohaib Cheema Profile Picture
    47,952 User Group Leader on at
    RE: Filter the records in Query Range based on Date in Ax 2012

    As per MSDN, Null value of date is treated as 1900-01-01  

    For CustTrans, if you will have a look at SQL SERVER DB, you will find that, the value of field Closed is not null, its 1900-01-01 00:00:00.000 on SQL SERVER

    So, passing dateNull() from X++ seems to fix the issue

    Give a try

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

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Mea_ Profile Picture

Mea_ 2

#2
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans