Solved

Enable/Disable Custom Command Button

  • 8 December 2023
  • 4 replies
  • 80 views

Userlevel 3
Badge

Hi All,

In my graph there are two custom buttons called Test1 and Test2. Initially I need to disable Test2 button and based on the condition in Test1 button need to Enable the Test2 button.

Here is my sample code

public PXAction<HMRCVendorRegisterDetail> Test1;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Button 1", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Enabled = false)]
protected virtual IEnumerable test1(PXAdapter adapter)
{
    if(x == 1)
    {
        Test2 button need to setEnable true here
    }
    else
    {
        Test2 button need to setEnable false here
    }
    return adapter.Get();
}

public PXAction<HMRCVendorRegisterDetail> Test2;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Button 2", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Enabled = false)]
protected virtual IEnumerable test2(PXAdapter adapter)
{
    return adapter.Get();
    
}

Can someone help me out?

Thanks

icon

Best answer by darylbowman 11 December 2023, 15:52

View original

4 replies

Userlevel 7
Badge +11

Hi @bhagyat25 

While it's possible to enable or disable fields or actions during row selected events, achieving the same within the button action is not straightforward. As an alternative, consider the following workaround: create an unbound field in the primary DAC, set the flag to true when you wish to enable the button, and then utilize this flag in the row selected event.

Badge +11

 Have you tried this?

if(x == 1)
{
//Test2 button need to setEnable true here
Test2.SetEnabled(true);
}
else
{
Test2 button need to setEnable false here
Test2.SetEnabled(false);
}

 

Userlevel 7
Badge +17

@bhagyat25 I would like to highlight a crucial point regarding code execution in Acumatica. It's imperative to handle enable/disable fields or actions exclusively in the RowSelected event. This serves as the primary rule for proper functionality.

In your case, introduce a new flag and set it TRUE when the button is clicked and based on the flag value write a code in the RowSelected event to enable/disable the actions accordingly. 

Userlevel 5
Badge +1

Hi everyone,

Actions have GetEnabled(), GetVisible() methods, that return bool value, here is example:

if (Test01.GetEnabled() == false)

{

  Test02.SetEnable(true);

}

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved