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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

filter a form with date filter using combo box in X++

(0) ShareShare
ReportReport
Posted on by 113

Hi Experts,
I want to open a form with Date filter  (today+1 ) using combo box .
This Datefilter (combo box) will  filter my Date field of custom form having only one DataSource.

I have created a combo box in form .
how to write logic for this condition.5824.Capture.PNG 

I have the same question (0)
  • Suggested answer
    Komi Siabi Profile Picture
    13,130 Most Valuable Professional on at

    You can use the QueryBuildDataSource object to achieve this. Overide the executeQuery of the datasource.

    dynamics365musings.com/.../

  • HARISH MEHRA Profile Picture
    113 on at

    4152.Capture.PNG

    [Form]
    public class ViewProductAvailability_CAP extends FormRun
    {
    
        [DataSource]
        class StockPredictions_CAP
        {
          
            public void executeQuery()
            {
                QueryBuildDataSource  queryBuildDataSource;
     
                queryBuildDataSource = this.query().dataSourceTable(tablenum(StockPrediction_CAP));
                queryBuildDataSource.clearRanges();
                queryBuildDataSource.addRange(fieldnum(StockPredictions_CAP, Date_CAP)).value(queryValue(Datefilter1.selection()));
                super();
            }
    
        }
    
        [Control("ComboBox")]
        class DateFilter1
        {
            public int selectionChange()
            {
                int ret;
        
                ret = super();
                StockPredictions_CAP_ds.executeQuery();
                return ret;
            }
           
        }
    
    }
    
    Hi Komi,

    Done all the things as per the post but getting the error

  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

    Hi Harish, I have done similar requirement to Display Records with Delivery date till today - 1 on click of Date Checkbox. This is how its been done and working.

    Added the date range in Form init method

    qbrPastDeliveryDate = this.queryBuildDataSource().addRange(fieldNum(SalesLineTmp, DlvDate));
    
    qbrPastDeliveryDate.value(SysQuery::range(DateTimeUtil::date(DateTimeUtil::minValue()), DateTimeUtil::getToday(DateTimeUtil::getUserPreferredTimeZone())-1));

    On Clicked method of Date Control to enable/disable range (AutoDeclaration of Date control to Yes)

    [Control("CheckBox")]
    class ShowPastDeliveryDateOnly
    {
       public void clicked()
       {
           super();
        
           qbrPastDeliveryDate.enabled(this.value());
           SalesLineTmp_ds.executeQuery();
       }
    }

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    Please have a look on this link. You need to use the modified method of this control.

    community.dynamics.com/.../filter-data-with-combobox

  • HARISH MEHRA Profile Picture
    113 on at

    Hello Mohit,

    Thanks for the reply.

    I tried your code . The thing I got - there is no clicked method in Combo box . so I used selection change method instead of that.

    I have written the code but getting some errors.

    Can you help me to resolve those.05732.Capture.PNG8764.Capture2.PNG

    [Form]
    public class ViewProductAvailability_CAP extends FormRun
    {
    
        
        /// 
        ///
        /// 
        public void init()
        {
            super();
    
            QueryBuildDataSource  queryBuildDataSource;
    
            DateFilter1 = this.queryBuildDataSource().addRange(fieldNum(StockPredictions_CAP, Date_CAP));
    
            DateFilter1.value(SysQuery::range(DateTimeUtil::date(DateTimeUtil::minValue()), DateTimeUtil::getToday(DateTimeUtil::getUserPreferredTimeZone()) 1));
        }
    
       
        [Control("ComboBox")]
        class DateFilter1
        {
            /// 
            ///
            /// 
            /// 
            public int selectionChange()
            {
                int ret;
        
                ret = super();
                
                DateFilter1.enabled(this.value());
                StockPredictions_CAP_ds.executeQuery();
    
                return ret;
            }
        }
    
    }
    

  • Mohit Rampal Profile Picture
    12,565 Moderator on at

    Hi Harish, What values do you have in Date Combobox?

  • Martin Dráb Profile Picture
    238,069 Most Valuable Professional on at

    The compiler is right - your code is full of basic errors.

    In init(), you declare queryBuildDataSource variable, but you don't use it for anything. Than you're calling this.queryBuildDataSource() method, but forms don't have such a method, as the compiler is telling you. You surely mean a data source, e.g. StockPredictions_CAP_ds.queryBuildDataSource().

    Then you try to assign a value of DateFilter1 variable, but you've never declared it.

    In selectionChange(), you're trying to use value() method, but no such a method exists. You can use selection() method, but it's not clear why you're using a combobox if your logic checks just whether the value is zero.

  • HARISH MEHRA Profile Picture
    113 on at

    Hi Mohit,

    getting the error on that also.

    One more thing . I have added a base 'TransDate' EDT in my DateFilter1(Combo box ) but when I am opening the form it is showing Enum options. Also I have change only two property of my Combo box . 1-  Auto Declare - Yes.

    2- Extended Data Type -TransDate.

    Why is this happening. Any Idea

    Thanks!

  • Mohit Rampal Profile Picture
    12,565 Moderator on at

    Do you want to show records till today + 1 date only? If yes, then shouldn't it be just checkbox to enable/Disable and code will fetch today's date and filter. May I know why you need TransDate filter.

  • HARISH MEHRA Profile Picture
    113 on at

    When   'ViewProductAvailability_CAP' form  using table -'StockPredictions_CAP' opens . my filter field- 'DateFilter1'  open with filter - today() +1.Which will also filter my Date_CAP field in my table.

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

News and Announcements

Season of Giving Solutions is Here!

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 679 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 429 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 264 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans