Skip to main content

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;
rPXButton(CommitChanges = true)]
tPXUIField(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

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.


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

 


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


Hi everyone,

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

if (Test01.GetEnabled() == false)

{

  Test02.SetEnable(true);

}


Reply