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 call command button click event through code

(0) ShareShare
ReportReport
Posted on by

Hello,

Can someone tell me, how to call the clicked event of the command button through the code.

I would like perform some operation within the code so that user manually doesnt have to click the button.

How can i achieve through envent handler.


Thanks

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

    Hi Jeff,

    Can you please elaborate on your question.

    Where you want to call the code on the clicked method.

    Thanks,

    Girish S.

  • JeffGreenrc Profile Picture
    on at

    I want to call click event of the button in lets say some form datasource method.

  • GirishS Profile Picture
    27,827 Moderator on at

    You can set the Auto declaration property of the command button control to Yes and then call ControlName.clicked().

    Thanks,

    Girish S.

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

    Adding to Girish using formrun you can get the control and call the clicked method if control has auto declaration no.

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

    Hi Jeff, I think Auto Declaration of command button cannot be changed in form extension for standard form. You can refer below code to access the command button via event handler. If you are using custom form then just change AutoDeclaration property of command button to Yes and access it directly in your code by control name.

       [FormDataSourceEventHandler(formDataSourceStr(MyDialogForm, SalesLine), FormDataSourceEventType::Activated)]
        public static void SalesLine_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
        {
            FormCommandButtonControl okButton = sender.formRun().design().controlName(identifierStr(OK));
            okButton.clicked();
        }

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

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans