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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Disable a form control before executeQuery and enable it afterwards.

(0) ShareShare
ReportReport
Posted on by 95

I am trying to disable (allowEdit=false or enabled = false) a date control before executeQuery method is called and enable it after the query has finished executing. 

This is to avoid having the user to click on the date controls multiple times while the query is still executing. 

I have a date range filter on a form that has a grid. The grid will reload based on value selected in the date controls. When the dates are modified, executeQuery on the form datasource is fired from the modified method of the control. I tried

- disabling-enabling the control before and after the executeQuery call in the modified method.

- It didn't work so moved the enabling to active method of the datasource.

- Also tried disabling in validate method and enabling in modified after executeQuery but none of them disables the control to avoid multiples clicks from user.

I removed the control.enabled(true) to make sure that it was being disabled to start with. It seems like a fairly easy thing to do but I am surely missing something. The date controls are not tied to any table fields. 

Thanks!

I have the same question (0)
  • Suggested answer
    Dynamics Community 101 Profile Picture
    310 on at

    when you enter the date values and click the ok button for the filter to execute

    write a code on the "clicked" method of the same button

    dateField.enable(0);

    executeQuery();

    dateField.enable(1);

    Kindly mark this thread 'Yes' if this is answered your query which may help other community members in this forum.

  • Priyan Profile Picture
    95 on at

    There is no Ok button for the query to start. It's when the user tabs out of the control that the validate and modified methods of the control are fired and the executeQuery is in the modified method.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Then you can do that in modified() instead of clicked().

  • Priyan Profile Picture
    95 on at

    That's the first place where I tried it, mentioned it in my original post.

    - disabling-enabling the control before and after the executeQuery call in the modified method.

    dateField.enabled(false);

    datasource_ds.executeQuery();

    dateField.enabled(true);

    While debugging when I stop at executeQuery call and check the form, the control is enabled. It's only when I remove this line dateField.enabled(true) that I see it disabled.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Then you would have the same problem with clicked().

    Let's start by creating a simpler test case than anybody can use to reproduce the problem:

    [Form]
    public class Form1 extends FormRun
    {
        void stop()
        {
            System.Diagnostics.Debugger::Break();
        }
    
        [Control("Date")]
        class FormDateControl1
        {
            public boolean modified()
            {
                boolean ret = super();
            
                this.enabled(false);
                element.stop();
                this.enabled(true);
            
                return ret;
            }
    
        }
    }

    I can confirm that the control is kept enabled. Now we can play with it and see if we can change that behaviour...

  • Verified answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    I guess you would have to somehow trigger a refresh of the web page on client and it's not clear to me how to do it. But there is another approach. Try something like this:

    void runQueryAndEnableFilters(AsyncTaskResult _result)
    {
        yourTable_ds.executeQuery();
        FormDateControl1.enabled(true);
    }
    
    [Control("Date")]
    class FormDateControl1
    {
        public boolean modified()
        {
            boolean ret = super();
            this.enabled(false);
            element.setTimeOutEx(formMethodStr(runQueryAndEnableFilters));
            return ret;
        }
    }

  • Priyan Profile Picture
    95 on at

    Thanks Martin! This approach works perfectly for my scenario. One minor correction formMethodStr takes 2 arguments.

    formMethodStr(yourFormName, runQueryAndEnableFilters);

    I am also looking into the possibility of doing a web page refresh as you suggested earlier.

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

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
Martin Dráb Profile Picture

Martin Dráb 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans