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

Announcements

No record found.

News and Announcements icon
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.

  • Suggested answer
    GirishS Profile Picture
    27,843 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,253 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,843 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,573 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,843 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,253 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 426 Most Valuable Professional

#2
CU10121822-0 Profile Picture

CU10121822-0 358

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 353 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans