Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Range Expression with date

(0) ShareShare
ReportReport
Posted on by 700

Dear community,

I am using an expression in query range and  my date range seem not to work:

qbr.value( strfmt( '  ((( %1.%2 == "%3" ) || (%1.%2 == "%4"))) &&   (( %1.%5 == "%6" )) ',        

queryLedgerTrans.dataSourceTable( TableNum( LedgerTrans )).name(), fieldStr( LedgerTrans, AccountNum ), queryValue(ProjParameters::find().customParameter ), queryValue(ProjParameters::find().customParameter2 ), fieldStr( LedgerTrans, TransDate ), SysQuery::range( fromDate, toDate )) ));


The first expression is successfully included, but the date range not. Is it crrect written? Or it is not possible to consider date ranges and I have to break down the range to  TransDate>= fromDate  && TransDate <= toDate ?

*This post is locked for comments

  • Suggested answer
    GirishS Profile Picture
    27,825 Moderator on at
    RE: Range Expression with date

    You can try like below and see whether it works.

     qbr.value( strfmt('((( %1.%2 != "%3" ) || (%1.%2 != "%4")))',        
        queryLedgerTrans.dataSourceTable(TableNum(TableName)).name(), 
                                    fieldStr(LedgerTrans, Date),                                
                                    queryValue(dateValue1), 
                                    queryValue(dateValue2)));

    Thanks,

    Girish S.

  • Menna Allah Ahmed Profile Picture
    163 on at
    RE: Range Expression with date

    How to make date not between this two dates ?

    I want to make trans date not in query range

  • OrangeRocks Profile Picture
    700 on at
    RE: Range Expression with date

    Thank you guys, it worked!

  • Verified answer
    Chaitanya Golla Profile Picture
    17,225 on at
    RE: Range Expression with date

    Hi,

    As suggested by Xiaoyun Fu, you need to define two ranges one on field AccountNum and another on field TransDate of table LedgerTrans. Your code typically looks like below

        QueryBuildRange qbr, qbr1;
        QueryBuildDataSource qbds;
        Query queryLedgerTrans;
        TransDate   fromDate, toDate;
        
        queryLedgerTrans = new Query();
        
        qbds = queryLedgerTrans.addDataSource(tableNum(LedgerTrans));
        qbr = qbds.addRange(fieldnum(LedgerTrans, AccountNum));
        
        qbr.value( strfmt('((( %1.%2 == "%3" ) || (%1.%2 == "%4")))',        
        queryLedgerTrans.dataSourceTable(TableNum(LedgerTrans)).name(), 
                                    fieldStr(LedgerTrans, AccountNum),                                
                                    queryValue(ProjParameters::find().custParameter), 
                                    queryValue(ProjParameters::find().custParameter2)));   
        
        
        qbr1 = qbds.addRange(fieldnum(LedgerJournalTrans, TransDate));
        qbr1.value(queryRange( fromDate, toDate));


  • Verified answer
    Xiaoyun Fu Profile Picture
    25 on at
    RE: Range Expression with date

    You could try using a separate the range for the TransDate condition instead of lump all the conditions in the expression:

    qbr = SysQuery::findOrCreateRange(qbdsLedgerTrans,fieldnum(LedgerTrans,TransDate));

    qbr.Value(SysQuery::range(fromDate, toDate));

    Let me know if this works!

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics AX (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 100 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 48

#3
shanawaz davood basha Profile Picture

shanawaz davood basha 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans