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

Announcements

News and Announcements icon
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
    Microsoft Employee 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
    305,475 Super User 2026 Season 1 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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 21

#2
dekion Profile Picture

dekion 4

#2
Virginia99 Profile Picture

Virginia99 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans