Skip to main content
Answer

What the correct way to update a custom field on an AR invoice after Release?

  • June 11, 2025
  • 2 replies
  • 62 views

Forum|alt.badge.img+1

I’ve got a custom field, let’s call it ARInvoice.UsrMyField

I want to update it after the invoice has been Released.

Handling the Release action in ARInvoiceEntryExt doesn’t seem to be the right way. I’ve tried:

 

        [PXOverride]
        public virtual IEnumerable Release(PXAdapter adapter)
        {
            IEnumerable result = null;
            // Acuminator disable once PX1008 LongOperationDelegateSynchronousExecution [Justification]
            PXLongOperation.StartOperation(Base, delegate
            {
                result = Base.release.Press(adapter);
            });
            PXLongOperation.WaitCompletion(Base.UID);

 

            Base.Document.Current.GetExtension<ARInvoiceEntryExt>().UsrMyField = “foo”;

            Base.Caches<ARInvoice>().UpdateCurrent();
            Base.SelectTimeStamp();

            Base.Caches<ARInvoice>().PersistUpdated(Base.Document.Current);

 

Throws a message to say “previous action not completed”. It then completes the update and performs the Release. So clearly the WaitCompletion had no effect.

 

I’ve also tried to use the OnReleaseComplete hook:

        public delegate List<ARRegister> ReleaseDocProcDelegate(JournalEntry je, ARRegister ardoc, List<Batch> pmBatchList, ARDocumentRelease.ARMassProcessReleaseTransactionScopeDelegate onreleasecomplete);

        [PXOverride]
        public List<ARRegister> ReleaseDocProc(JournalEntry je, ARRegister ardoc, List<Batch> pmBatchList, ARDocumentRelease.ARMassProcessReleaseTransactionScopeDelegate onreleasecomplete, ReleaseDocProcDelegate del)
        {
            onreleasecomplete += OnReleaseComplete;
            return del(je, ardoc, pmBatchList, onreleasecomplete);
        }

 

        public void OnReleaseComplete(ARRegister doc)
        {
            try
            {
                if (doc is ARInvoice invoice)
                {
                    UpdateTheInvoice(invoice);

                    Base.Caches<ARInvoice>().Update(doc);
                    Base.SelectTimeStamp();

                    Base.Caches<ARInvoice>().PersistUpdated(doc);
                }
            }
            catch (Exception exc)
            {
                PXTrace.WriteError(exc);
            }
        }

 

And while I don’t get the ‘another process has updated the record’ error, It also doesn’t do what I expect.

It succeeds; and I can see the updated value on the screen if I put a breakpoint in there, but then it reverts the invoice to the copy that it cached before calling the onreleasecomplete method.

 

It feels like I’m missing a line of code, but can’t think what it might be?

Best answer by darylbowman

Instead of overriding the action, try extending it:

public virtual IEnumerable ReleaseDelegate(PXAdapter adapter);
[PXOverride]
public virtual IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
{
baseMethod(adapter);

PXLongOperation.WaitCompletion(Base.UID);

var doc = Base.Document.Current;
Base.Document.SetValueExt<ARInvoiceEntryExt.usrMyField>(doc, "foo");
Base.Document.Update(doc);
Base.Persist();
}

 

2 replies

darylbowman
Captain II
Forum|alt.badge.img+15
  • Answer
  • June 11, 2025

Instead of overriding the action, try extending it:

public virtual IEnumerable ReleaseDelegate(PXAdapter adapter);
[PXOverride]
public virtual IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
{
baseMethod(adapter);

PXLongOperation.WaitCompletion(Base.UID);

var doc = Base.Document.Current;
Base.Document.SetValueExt<ARInvoiceEntryExt.usrMyField>(doc, "foo");
Base.Document.Update(doc);
Base.Persist();
}

 


Forum|alt.badge.img+1

That did the trick!

 

Thanks