How to add a custom Mass Action button to a GI in Acumatica

210 views Asked by At

Using Build 21.210.0030

I’m a bit of a ‘noob’ to Acumatica dev and I have a question concerning toolbar buttons on a Generic Inquiry (GI) with the intention of performing a Mass Action. The following PXAction works on the Vendor form (../Main?ScreenId=AP303000&AcctCD=AASERVICES):

public class VendorMaint_Extension : PXGraphExtension<VendorMaint>
{
    public SelectFrom<PX.Objects.CR.BAccount>.View suppliers;

    #region buttons
    public PXAction<PX.Objects.CR.BAccount> myButton;

    [PXButton(CommitChanges = true)]
    [PXUIField(DisplayName = "Verify Now", IsDirty = true)]
    public virtual IEnumerable MyButton(PXAdapter adapter)
    {
        BAccount supplier = suppliers.Current;
        PX.Objects.CR.BAccountExt bAccountExt = PXCache<BAccount>.GetExtension<PX.Objects.CR.BAccountExt>(supplier);

        // do my stuff...
        //...
        //...

        return adapter.Get();
    }
    #endregion buttons
    //...
    //...

My GI is a filtered copy of AP-Vendors (AP3030PL) but I can’t get my button to display in the list of available Mass Actions. I’ve tried adding the following in the class (above)

public override void Initialize()
{
    base.Initialize();
    myButton.IsMass = true;
    Base.action.AddMenuAction(this.myButton);
}

and I’ve tried many variations of this Initialize method but none seem to make a difference. I've also tried to implement the answers provided in these previous questions (to no avail):

How to add action button in Inquiry page? and Add Custom action to GI Mass Actions dropdown

I think part of my issue is that I don't fully understand whether to use BAccount, VendorR and/or Vendor yet.

I fully accept that I might be doing it all wrong so any and all help will be gratefully appreciated.

Thanks

1

There are 1 answers

0
Gav D On BEST ANSWER

Turns out it was relatively straight-forward, very similar to the way processing forms work. I had to change the button from a PXButton to a PXProcessButton in my VendorMaint_Extension class and move the code (that does the actual work) into a static method used by the PXLongOperation e.g.

```
    [PXProcessButton(CommitChanges = true)]
    [PXUIField(DisplayName = "Verify Now", IsDirty = true)]
    public virtual IEnumerable MyButton(PXAdapter adapter)
    {
        bool isMassProcess = adapter.MassProcess;

        List<BAccount> vendorList = new List<BAccount>();
        foreach (BAccount bAcc in adapter.Get<BAccount>())
        {
            PX.Objects.CR.BAccountExt bAccountExt = PXCache<BAccount>.GetExtension<PX.Objects.CR.BAccountExt>(bAcc);
            if (bAccountExt.UsrIsSomething == true)
            {
                vendorList.Add(bAcc);
            }
        }

        // trigger the Save action to save changes in the database.
        Base.Save.Press();
        PXLongOperation.StartOperation(this, delegate ()
        {
            DoMyStuff(vendorList, isMassProcess);
        });

        return vendorList;
    }
```