How to Enable/Disable a Form Button with X++

To enable or disable button in form based on current selected record status through event handlers.

Create a button or choose a button to enable / disable in form.

Go to Form/Datasource/Events/OnActivated, right click and select "Copy event handler for OnActivated method".




 

Create new class NNT_WHSWorkTableFormEventHandlers


class NNT_WHSWorkTableFormEventHandlers

{

    [FormDataSourceEventHandler(formDataSourceStr(WHSWorkTableListPage, WHSWorkTable), FormDataSourceEventType::Activated)]

    public static void WHSWorkTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)

    {

        #define.BTNNAME('YourButtonName')

        WHSWorkTable whsWorkTable = sender.cursor();

        FormRun element = sender.formRun();

        FormControl YourButton = element.design(0).controlName(#BTNNAME);

        YourButton.enabled(whsWorkTable.WorkTransType != WHSWorkTransType::Sales);

    }

}

 

Build the solution and refresh your browser.

 

We can see the button disabled in form.






 

 

Comments

Popular posts from this blog

How to customize electronic reporting in D365

Batch parallelism or multithreading in Dynamics 365 for Finance and Operations

How to create and run the Runbase batch class in D365

Build HTML and send email in D365 FO with X++

Difference between InMemory and TempDB tables in D365 F&O

Conditional Statements in X++

How to apply a package in LCS Dynamics 365 F&O

Customize the standard excel template in D365FO

How to write the event handler in D365