Solved

How to override public virtual bool Approve(SourceAssign source) Method

  • 2 November 2021
  • 3 replies
  • 135 views

Userlevel 7
Badge +9

I need to override a piece of Acumatica’s Approval process that prevents from Apprving a Rejected document. Not sure why Acumatica has put this control in place but it happens many times for us that a documents gets rejected to add some supporting documents and when documentation completed, then this document can be approved. The piece of the code that prevents from approving a rejected document is in EP\Descriptor\Attributes.cs as follows:

 

        public virtual bool Approve(SourceAssign source)
        {
            EPApproval item = (EPApproval)this._Rejected.SelectSingle(GetSourceNoteID(source));

            if (item != null)
                throw new PXException(Messages.CannotApproveRejectedItem);

            if (UpdateApproval(source, EPApprovalStatus.Approved))
            {
                RegisterActivity(source, PO.Messages.Approved);

                return true;
            }

            return false;
        }

icon

Best answer by aaghaei 5 November 2022, 00:55

View original

3 replies

Userlevel 2
Badge

Hi, Do you have any solution for this ?. 

Userlevel 5
Badge +1

Hi, If you need to override this method, you could use this syntax:

 

[PXOverride]

public virtual bool Approve(SourceAssign source, Func<SourceAssign, bool> baseMethod)

{

// do your staff, code logic

// invoke base Acumatica’s method

bool returnBoolValue = baseMethod(source);

if (returnBoolValue == true)

   {

       // do your staff

   }

}

Userlevel 7
Badge +9

thanks, @andriikravetskyi35 , and hi @arun83 @Chris Hackett 

with the above syntax, the base method will be called first I guess by the framework not the overridden one. In fact, I am not sure if the overridden method will be called at all. I believe the correct syntax is as follows. @arun83 please test to see which one will work best in your case.

[PXOverride]
public override bool Approve(SourceAssign source)
{
// Do Stuff Here

// Invoke Acumatica’s base method or simply do not call it if you don't need it.
bool baseValue = base.Approve(source);

// Do Stuff Here

return ?;
}

 

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