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)

Date range in query value

(0) ShareShare
ReportReport
Posted on by

Hi

I have next code in lookup: 

public void lookup()
{
    Query query = new Query();
    QueryBuildDataSource queryBuildDataSource;
    QueryBuildRange queryBuildRange;
     QueryBuildRange queryBuildRange2;
     QueryBuildRange queryBuildRange3;

    SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(SalesTable), this);

    if(DateFrom.dateValue() && DateTo.dateValue())
    {
        sysTableLookup.addLookupfield(fieldNum(SalesTable, CustAccount));

        queryBuildDataSource = query.addDataSource(tableNum(SalesTable));

        queryBuildDataSource.addGroupByField(fieldNum(SalesTable, CustAccount));

        queryBuildRange = queryBuildDataSource.addRange(fieldNum(SalesTable, createdDateTime));
        queryBuildRange.value(SysQuery::range(this.dboConvertDateToDateTime(DateFrom.DateValue()), dateNull()));

        queryBuildRange = queryBuildDataSource.addRange(fieldNum(SalesTable, createdDateTime));
        queryBuildRange.value(SysQuery::range(dateNull(), this.dboConvertDateToDateTime(DateTo.dateValue())));

        queryBuildRange = queryBuildDataSource.addRange(fieldNum(SalesTable, InventSiteId));
        queryBuildRange.value(editInventSiteId.text());

        sysTableLookup.parmQuery(query);

        sysTableLookup.performFormLookup();

    }
    //super();


Value of this query is:

Query  object 2bffea00: SELECT * FROM SalesTable(SalesTable_1) GROUP BY SalesTable.CustAccount WHERE ((createdDateTime>='2015-01-03T00:00:00') OR (createdDateTime<='2015-01-04T00:00:00')) AND ((InventSiteId = N'4'))


Here show OR between two dates, but need AND. How write correct Date range in query?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    You need to create expression in Range value

    some thing line this

    strFmt('((A == %1) && (B == %2))',x,y)

  • Verified answer
    Community Member Profile Picture
    on at

    Please follow following link for more details

    msdn.microsoft.com/.../aa893981.aspx

    Please verify and let me know if it solves your problem

  • Verified answer
    Ivan (Vanya) Kashperuk Profile Picture
    on at

    No, don't use extended ranges, it is not necessary here.

    You were using the range method correctly (almost).

    Replace your code:

           queryBuildRange = queryBuildDataSource.addRange(fieldNum(SalesTable, createdDateTime));
    
           queryBuildRange.value(SysQuery::range(this.dboConvertDateToDateTime(DateFrom.DateValue()), dateNull()));
    
           queryBuildRange = queryBuildDataSource.addRange(fieldNum(SalesTable, createdDateTime));
    
           queryBuildRange.value(SysQuery::range(dateNull(), this.dboConvertDateToDateTime(DateTo.dateValue())));
    

    with this:

           queryBuildRange = queryBuildDataSource.addRange(fieldNum(SalesTable, createdDateTime));
    
           queryBuildRange.value(SysQuery::range(this.dboConvertDateToDateTime(DateFrom.DateValue()), this.dboConvertDateToDateTime(DateTo.dateValue())));
    


  • maxhammer Profile Picture
    on at

    thank you, i litle changed and now work.

  • André Arnaud de Calavon Profile Picture
    301,035 Super User 2025 Season 2 on at

    Hi Maxhammer,

    Would you mind to indicate which answer helped and did not helped you? Then this thread will get the status answered and other community members will be directed to the correct answer.

  • maxhammer Profile Picture
    on at

    helped from Ivan:

     queryBuildRange = queryBuildDataSource.addRange(fieldNum(SalesTable, createdDateTime));
     
           queryBuildRange.value(SysQuery::range(this.dboConvertDateToDateTime(DateFrom.DateValue()), this.dboConvertDateToDateTime(DateTo.dateValue())));


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