Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

How to enable/disable buttons on Edit button (in action pane) of a Standard form?

(0) ShareShare
ReportReport
Posted on by 159

Hi experts,

Basically, I have created a custom workflow on item arrival in Inventory Management and I will attach the screenshot below.

I have a requirement to disable few buttons like validate and Post when the workflow stage is in Draft. I have done this part by writing a code in datasource active method and it is working fine but when I click the Edit button or when the form is in edit mode the two buttons(Validate and Post) got enable. I have researched my self and I found the code below for how to add logic to edit button and here is the code:

class WMSJournalTable_Form_EventHandler
{

[FormEventHandler(formStr(WMSJournalTable), FormEventType::Initialized)]
     public static void WMSJournalTable_OnInitialized(xFormRun sender, FormEventArgs e)
     {
         WMSJournalTable_Form_EventHandler myEventHandler = new WMSJournalTable_Form_EventHandler();
         FormRun formRun = sender as FormRun;
         formRun.viewEditModeHelper().EditModeSwitched += eventhandler(myEventHandler.enableButtons);

     }

public void enableButtons()
     {
         info("Inside event handler");

     }

}

When I click on edit button the info message is shown meaning the eventHandler is working fine but now how can I access the FormContols in my enableButtons() method because my requirement is to enable/disable the buttons (Validate and Post). I have also tried to pass the sender as a parameter to enableButtons but it shows some error. So, anyone have any suggestion which can help me out with this?

You any suggestion would be highly appreciated!

pastedimage1678889917765v1.png

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,552 Super User 2024 Season 1 on at
    RE: How to enable/disable buttons on Edit button (in action pane) of a Standard form?

    Hi Arif, You should use chain of commands instead of event handlers as accessing form controls is more easier. I don't think you need to use these delegates.

    Create an extension class for form and create enableButtonsActive method in extension class and using chain of command you can access all form controls.

    You can see how I have used PostJournal Form control directly in my extension class

    pastedimage1679107166998v1.png

  • Arif Hussain Profile Picture
    Arif Hussain 159 on at
    RE: How to enable/disable buttons on Edit button (in action pane) of a Standard form?

    Hi sir Mohit Rampal ,

    I am just following if you got a chance to check my above mentioned code. Can you please help me out with this? I would highly appreciate your response.

    Regards,

    Arif

  • Arif Hussain Profile Picture
    Arif Hussain 159 on at
    RE: How to enable/disable buttons on Edit button (in action pane) of a Standard form?

    Hi Mohit, again your response is appreciated.

    I know getting the formControl in an eventHanlder and I also know how to extend formControlStr but my issue is that I am unable to get the controls in my public void enableButtons() method as I think it is a delegate. How can I pass the sender of eventHandler as a parameter to my enableButtons. I tried it in simple ways but it was showing an error.

    Please look into my code again. I think you will understand what do I want to achieve.

    Here is a link and screenshot which I followed:

    learn.microsoft.com/.../system-defined-buttons

    pastedimage1678967892010v1.png


    pastedimage1678967917467v2.png

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,552 Super User 2024 Season 1 on at
    RE: How to enable/disable buttons on Edit button (in action pane) of a Standard form?

    You just need access to formRun and then can access all controls in form Design.

    Check this article

    community.dynamics.com/.../form-event-hander-methods-in-dynamics-365-fo-dyn365fo

    Using Chain of command

    dynamics365musings.com/.../

  • Arif Hussain Profile Picture
    Arif Hussain 159 on at
    RE: How to enable/disable buttons on Edit button (in action pane) of a Standard form?

    Hi Mohit Rampal  again,

    The solution you provided is working fine and I good with that. But for my knowledge, what if we need to add some custom logic when an edit or new button is clicked?

    As mentioned I now know the eventhandlers for this but I am still unable to get the controls in those event handlers. Can you please tell me how to get those?

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,552 Super User 2024 Season 1 on at
    RE: How to enable/disable buttons on Edit button (in action pane) of a Standard form?

    Glad, I could help. Let us know if still any issues.

  • Arif Hussain Profile Picture
    Arif Hussain 159 on at
    RE: How to enable/disable buttons on Edit button (in action pane) of a Standard form?

    Thank you Mohit Rampal , you really saved my day.

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,552 Super User 2024 Season 1 on at
    RE: How to enable/disable buttons on Edit button (in action pane) of a Standard form?

    Hi Arif, Please verify its same form you are referring

    pastedimage1678953569354v1.png

  • Arif Hussain Profile Picture
    Arif Hussain 159 on at
    RE: How to enable/disable buttons on Edit button (in action pane) of a Standard form?

    Hi Mohit Rampal ,

    I really appreciate your suggestion. But I could not find the 'enableButtonsActive' method on form. Can you please verify it please.

    Regards,

    Arif

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,552 Super User 2024 Season 1 on at
    RE: How to enable/disable buttons on Edit button (in action pane) of a Standard form?

    Hi Arif, There is a form method 'enableButtonsActive' which should be used for this purpose. You don't need to control those controls based on Edit button. Instead, you can create an Extension class for this form and access the controls directly (For controls where Auto Declaration is Yes)

    For Example

    checkJournal.enabled(wmsJournalTable.Posted);

    You can replace wmsJournalTable.Posted with wmsJournalTable.ApprovalField == WorkflowEnum::Draft

    For fields where Auto declaration is not set to Yes, controls can be accessed as mentioned in below article

    devserra.wordpress.com/.../

    We have extend same method and controlling post button based on some custom fields & conditions.

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…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,817 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans