Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Extract FromDate and ToDate From Date Advanced Filtering Input

(0) ShareShare
ReportReport
Posted on by 1,206

Hi,

I'm creating a form grid view with working calendar dates as the main datasource. User should be able to filter date range using advanced filter like 1/3/2019..31/3/2019

date-advanced-filter.png

The query range is like Date >= 1/3/2019 && Date <= 31/3/2019.

Is there any way to extract the input values and store 1/3/2019 as FromDate and 31/3/2019 as ToDate? 

I'd like to use these values for comparison with each line of it's child data source later.

Thank You.

*This post is locked for comments

  • HAIRUL HAZRI Profile Picture
    HAIRUL HAZRI 1,206 on at
    RE: Extract FromDate and ToDate From Date Advanced Filtering Input

    Thank you Ievgen. It works. 

    Here's my completed code in case somebody needs it:

    Query                   query;
    QueryRun                queryRun;
    QueryBuildDataSource    qbdsWorkCalendarDate;
    QueryBuildRange         qbrProductionDate, dateRange;
    int                     rmFromDate, rmToDate;
    str                     dateRangeValue, fromDateStr, toDateStr;
    TransDate               fromDate, toDate;
    
    query = new Query();
    
    //define data sources
    qbdsWorkCalendarDate = query.addDataSource(tableNum(WorkCalendarDate));
    
    qbrProductionDate = qbdsWorkCalendarDate.addRange(fieldNum(WorkCalendarDate, TransDate));
    
    qbdsWorkCalendarDate.addOrderByField(fieldNum(WorkCalendarDate, TransDate));
    
    queryRun = new QueryRun(query);
    
    if (queryRun.prompt())
        {
            while(queryRun.next())
            {
                //After prompt, range is specified. So query is modified. Get modified query range value. Otherwise query only has range but without value.
                query = queryRun.query();
                qbdsWorkCalendarDate = queryRun.query().dataSourceTable(tablenum(WorkCalendarDate));
                dateRange = qbdsWorkCalendarDate.findRange(fieldNum(WorkCalendarDate,TransDate));
                dateRangeValue = dateRange.value();
                
                //Extract from date
                rmFromDate = strFind(dateRangeValue,"..",1,strLen(dateRangeValue));
                fromDateStr = strDel(dateRangeValue, rmFromDate, strLen(dateRangeValue));
                fromDate = str2Date(fromDateStr, 123);
                
                
                //Extract toDate
                rmToDate = strFind(dateRangeValue,"..",1,strLen(dateRangeValue));
                toDateStr = strDel(dateRangeValue, 1, rmToDate + 1);
                toDate = str2Date(toDateStr, 123);
                
                info(strFmt("From %1 To %2", fromDate, toDate));
            }
        }


  • Verified answer
    Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: Extract FromDate and ToDate From Date Advanced Filtering Input

    Filter you add is effectively a query range. Let's say you have QueryBuildDataSource (qbds), to get range value you do

    dateRange = qbds.findRange(fieldNum(MyTable, MyField));
    if (dateRange )
    {
        info(dateRange.value());
    }

    and you can always get qbds from a query by table id.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans