How to: Enable and Disable an Action Pane Button on a List Page using Interaction Class in Ax 2012

To enable or disable an action pane button

  1. In the AOT, expand Forms and find the form for the list page where the action pane button appears. Use the InteractionClass property of the form to get the name of the interaction class for the list page.
  2. Expand Designs, expand Design, and then expand the Action Pane. Get the name of each action pane button that you want to enable or disable based on the list selection.
  3. Expand Classes, right-click the interaction class for the list page, click Override Method, and then click selectionChanged. The Editor window opens and displays theselectionChanged method.
  4. Use the list page activeRecord method to get a reference to the current record in the list page grid. To use the method, you have to supply the name of the data source for the list page.The following code example shows how to reference the current record in a grid that shows customer records. Notice the use of the queryDataSourceStr function to specify the name of the data source. In the example, CustTableListPage is the name of the query and CustTable is the data source of that query.
    Public void selectionChanged()
    {
        CustTable custTableCurrent = this.listPage().activeRecord(queryDataSourceStr(CustTableListPage, CustTable));
        
        super(); 
    }
    
  5. Add the criteria that you use to enable or disable the action pane button.For example, you have a button in the action pane of a customer list page that you use to assign a credit limit to a customer. If the customer already has a credit limit, you want that button to appear as a disabled button. If the customer does not have a credit limit, you want that button to appear as an enabled button.
  6. Use the actionPaneControlEnabled method of the list page to enable or disable the button. To use the method, you specify the name of the button control and whether to enable or disable the control.The following code example shows how to enable or disable a specified action pane button. Notice the use of the formControlStr function to get the name of the button control. In the example, CustTableListPage is the name of the form and SetCreditMax is the name of action pane button.
     Public void selectionChanged()
    {
        CustTable custTableCurrent = this.listPage().activeRecord(queryDataSourceStr(CustTableListPage, CustTable));
        
        super();
        
        if(custTableCurrent.CreditMax > 0)
        {
            this.listPage().actionPaneControlEnabled(formControlStr(CustTableListPage, SetCreditMax), false);
            
        }
        else
        {
            this.listPage().actionPaneControlEnabled(formControlStr(CustTableListPage, SetCreditMax), true);
            
        }
    }
    
  7. In the Editor window, click Compile. Close the Editor window.

For more: https://msdn.microsoft.com/en-us/library/cc570334.aspx

Advertisements

One comment on “How to: Enable and Disable an Action Pane Button on a List Page using Interaction Class in Ax 2012

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s