Skip to main content
Answer

Enable/Disable Custom Command Button

  • December 8, 2023
  • 4 replies
  • 201 views

Forum|alt.badge.img

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

Best answer by darylbowman

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

 

4 replies

jinin
Pro I
Forum|alt.badge.img+11
  • Pro I
  • December 8, 2023

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.


darylbowman
Captain II
Forum|alt.badge.img+15
  • Answer
  • December 11, 2023

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

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • December 11, 2023

@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. 


andriikravetskyi35
Jr Varsity I
Forum|alt.badge.img+1

Hi everyone,

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

if (Test01.GetEnabled() == false)

{

  Test02.SetEnable(true);

}