Solved

Capture the ParentBAccountID to ARRegister during invoice release

  • 24 May 2023
  • 8 replies
  • 78 views

Userlevel 4
Badge

I created a UDF in ARRegister called UsrInvParent (datatype INT), in the ARRegister table.

What I want to do is save the ParentBAccountID of the customer BAccount on the invoice to this new UsrInvParent UDF upon the “Release” of the invoice.

So, using customization what is the best way to code this in Acumatica? (if someone could provide an example, I would greatly appreciate that also.)

(The reason for the new UDF is that our customers quite often change parent accounts due to acquisitions and we need to capture the parent account at the time of invoice for historical reporting.)

I hope I am being clear as to what I am wanting to do.
 

Thank you so much!
 

NOTE :
I am trying to do in Acumatica with an Invoice Release what I can do in SQL with the following command.
UPDATE AR
SET AR.UsrInvParent = Cust.ParentBAccountID
FROM [dbo].[ARRegister] AR
INNER JOIN
[dbo].[BAccount] Cust
ON AR.CustomerID = Cust.BAccountID
WHERE AR.[CompanyID] = 2
AND AR.[CustomerID] = 26603

icon

Best answer by darylbowman 26 May 2023, 15:41

View original

8 replies

Badge +10

I would suggest overriding the Release action and performing the field update during the override.

This answer may assist in writing the Release override: https://community.acumatica.com/develop-customizations-288/how-to-override-an-action-in-a-graph-extension-11328

Userlevel 4
Badge

@darylbowman Thank you for the link. 

I read through that and, frankly, I am not following how that works and where and how in the code logic I would update the UDF.  (I am still learning the Acumatica C# code functions)

Also, in our instance, it appears there is another customization that already performs a release override; would I create a conflict?

Finally, in the example given it refers to SOOrder, would that class also pickup both the AR301000 and SO303000 screen functions for creating an invoice?  (again my apologies if this is a stupid or naive question.)
Jeff

Badge +10

Ordinarily, I think this would do it, and you’d want it in a graph extension of ARInvoiceEntry:

public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);
public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
{
var result = baseMethod(adapter);

ARRegister register = Base.Document.Current;
Customer customer = Customer.PK.Find(Base, register.CustomerID);
Base.Document.SetValueExt<ARRegisterExt.usrInvParent>(register, customer.ParentBAccountID);

return result;
}

I’m not honestly sure how it works to have multiple overridden actions.

Userlevel 4
Badge

@darylbowman Thank you!

I will give that a go later this evening and post back here if I have an issue.

Userlevel 4
Badge

@darylbowman 
This is where my knowledge regarding Acumatica completely breaks down.  There are so many graph extensions with ARInvoiceEntry  in them, I simply chose the first in the list.  

However, during validation/compile I have the error below.

Building directory '\WebSiteValidationDomain\App_RuntimeCode\'.
\App_RuntimeCode\ARInvoiceEntry.cs(58): error CS1503: Argument 1: cannot convert from 'PX.Objects.AR.ARRegister' to 'PX.Objects.AR.ARInvoice'
\App_RuntimeCode\ARInvoiceEntry.cs(58): error CS1503: Argument 1: cannot convert from 'PX.Objects.AR.ARRegister' to 'PX.Objects.AR.ARInvoice'

Here is the code in the extension below.  What am I doing wrong here? (for future reference, how do I know I am choosing the right graph to extend?

-------------------------------------

namespace PX.Objects.AR
{
  public class ARInvoiceEntry_Extension : PXGraphExtension<PX.Objects.AR.ARInvoiceEntry>
  {
    #region Event Handlers
    public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);
    public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
    {
      var result = baseMethod(adapter);
    
      ARRegister register = Base.Document.Current;
      Customer customer = Customer.PK.Find(Base, register.CustomerID);
      Base.Document.SetValueExt<ARRegisterExt.usrInvParent>(register, customer.ParentBAccountID);
    
      return result;
    }
    #endregion
  }
}

 

Badge +10

You did that right. This was my fault. Replace ARRegister with ARInvoice everywhere except ARRegisterExt.

Badge +10

Hey @jeffgrammer69 

 

I just realized I missed the [PXOverride] attribute above the method. That may present issues.

It should be:

namespace PX.Objects.AR
{
public class ARInvoiceEntry_Extension : PXGraphExtension<PX.Objects.AR.ARInvoiceEntry>
{
#region Event Handlers
public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);

[PXOverride]
public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
{
var result = baseMethod(adapter);

ARInvoice invoice = Base.Document.Current;
Customer customer = Customer.PK.Find(Base, invoice.CustomerID);
Base.Document.SetValueExt<ARRegisterExt.usrInvParent>(invoice, customer.ParentBAccountID);

return result;
}
#endregion
}
}

 

Userlevel 4
Badge

Good evening Daryl!

My apologies for taking so long to respond.  I was traveling on Friday.

The [PXOverride] missing was exactly what was causing me some issues and I did not realize I needed that command in there.

This works PERFECTLY!  And works from either the SO302000 or AR301000 screens.  

Thank you!

 

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