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)

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

I have the same question (0)
  • Verified answer
    Xiaoyun Fu Profile Picture
    25 on at

    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!

  • Verified answer
    Chaitanya Golla Profile Picture
    17,225 on at

    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));


  • OrangeRocks Profile Picture
    700 on at

    Thank you guys, it worked!

  • Menna Allah Ahmed Profile Picture
    163 on at

    How to make date not between this two dates ?

    I want to make trans date not in query range

  • Suggested answer
    GirishS Profile Picture
    27,843 Moderator on at

    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.

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 May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 10

#2
Harisgillani Profile Picture

Harisgillani 4

#2
dserp Profile Picture

dserp 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans