Skip to main content

Notifications

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

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: how to call command button click event through code

    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();
        }

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: how to call command button click event through code

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

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: how to call command button click event through code

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

    Thanks,

    Girish S.

  • JeffGreenrc Profile Picture
    JeffGreenrc on at
    RE: how to call command button click event through code

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

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: how to call command button click event through code

    Hi Jeff,

    Can you please elaborate on your question.

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

    Thanks,

    Girish S.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,074 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,900 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans