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

Notifications

Announcements

No record found.

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)
  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    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

  • Suggested answer
    Iulian Cordobin Profile Picture
    8,201 on at

    Try like this:

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

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

  • Verified answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    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()));
  • Tony Mok Profile Picture
    577 on at

    Hi Martin Dráb,

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

  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    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?

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…

Neeraj Kumar – Community Spotlight

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

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans