Skip to main content
Answer

Custom button click event fire twice.

  • December 6, 2023
  • 2 replies
  • 141 views

Forum|alt.badge.img

Hi,

In my graph I’ve a custom button(Verify Vendor) and that button click event fire again press OK on the WebDialogResult popup comes up. 

Here is my screen shot and the click event.

public PXAction<HMRCVendorRegisterDetail> VerifyVendor;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Verify Vendor", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Enabled = false)]
protected virtual IEnumerable verifyVendor(PXAdapter adapter)
{
    //Logics here
    
    if(VendorRegisterDetail.Current.BAccountID == null)
    {
        WebDialogResult result = VendorRegisterDetail.Ask(ActionsMessages.Warning, Messages.VendorEmptyMessage,
        MessageButtons.OK, MessageIcon.Warning, true);
    }
    
    return adapter.Get();
}

Can someone help me out to solve this issue?

Thanks

Best answer by Vipul Gajara

@bhagyat25, Since you are using a custom Action, PXLongOperation would be a best option to validate and display the message.

PXLongOperation.StartOperation(this, delegate ()
{
if (VendorRegisterDetail.Current.BAccountID == null)
    {
    var message = "Your message here";
    throw new PXException(message);
    }
}); 

 

2 replies

Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • December 6, 2023

That’s the way it works. Every Ask method eventually throws a special exception that is being handled somewhere up the call stack. To return the execution to the same place, the framework “remembers” the method the exception has been thrown from and re-executes that method once the exception has been dealt with.

 

If your intention is to just show a warning, I’d recommend just putting the warning on a field using RaiseExceptionHandling method instead of using Ask.

 


  • Freshman III
  • Answer
  • December 6, 2023

@bhagyat25, Since you are using a custom Action, PXLongOperation would be a best option to validate and display the message.

PXLongOperation.StartOperation(this, delegate ()
{
if (VendorRegisterDetail.Current.BAccountID == null)
    {
    var message = "Your message here";
    throw new PXException(message);
    }
});