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, ...
Suggested Answer

How to override an active method for button disabling in a form in x++

(0) ShareShare
ReportReport
Posted on by 5

Hi,

I have a condition to disable few buttons until a record is created in that form. In order words, when the selects the existing record or when he creates a new record, the button should be visible or enable.

Consider the button names as open and close.

Thanks in advance.

I have the same question (1)
  • Suggested answer
    GirishS Profile Picture
    27,827 Moderator on at

    Hi Barath,

    You can use FormDatasourceName to check whether there is any record or not. Based on that you can enable disable button.

    Make the Auto declaration of the button control to Yes. Assuming it as a custom form.

    public int active()
    {
        int ret = super();
        if(FormDataSourceName.RecId)
        {
            control.enabled(true);
        }
        else
        {
            control.enabled(false);
        }
        return ret;
    }

    Thanks,

    Girish S.

  • Suggested answer
    Komi Siabi Profile Picture
    13,107 Most Valuable Professional on at

    Hello Barath,

    Going by design, you might want to enable/disable a button or a form control based on another field of the current record on a form.

    An example is, you want to disable the post button on a journal when the posted field is NoYes::Yes.

    This thread will give you an idea.

    community.dynamics.com/.../how-to-disable-a-button-on-a-form-based-on-the-selected-record

  • Barath Ram J Profile Picture
    5 on at

    I didnt quite get this one.

    Whether it is helpful to enable or disable specific button alone in a form, for example I have mentioned only 2 buttons open and close. If so, I have to change this line of code to what ?

    control.enabled(true)

  • GirishS Profile Picture
    27,827 Moderator on at

    you need to mention both the controls.

    control1.enabled(true);

    control2.enabled(true);

    Thanks

    Girish S.

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

    Hi, if your requirement is to enable the buttons only when form has some records then you can use NeedRecords property in buttons in your form.

  • Barath Ram J Profile Picture
    5 on at

    Can you confirm whether this is appropriate

    Open.enabled(true);

    Close.enabled(true);

  • GirishS Profile Picture
    27,827 Moderator on at

    Yes like that you need to add.

    Thanks,

    Girish S.

  • Barath Ram J Profile Picture
    5 on at

    Hi Mohit,

    Thanks for your info. But I have already enabled it but that didnt work.

    Thanks,

    Barath Ram J

  • C4u Profile Picture
    70 on at

    If this has to be implemented in active method, can you send a full set of sample code to implement this one ? I am getting lots of error while trying this.

  • Komi Siabi Profile Picture
    13,107 Most Valuable Professional on at

    Hi C4u,

    Please, do you have the exact requirements as Barath Ram?

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 646 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans