Question

Run extension code after Remove From Hold in Sales Order assigns Order Number


Userlevel 2
Badge

I am trying to execute code to check if a customer qualifies for our reward program.  It needs to run when the order is removed from hold but after the SOOrder.OrderNbr is assigned.  Right now the value is <NEW> when I write the reward record to my custom table.

 

public delegate IEnumerable ReleaseFromHoldDelegate(PXAdapter adapter);
[PXOverride()]
public IEnumerable ReleaseFromHold(PXAdapter adapter, ReleaseFromHoldDelegate BaseMethod)
{
    BaseMethod(adapter);
    SOOrder row = Base.Document.Current;
    if (row != null)
    {
        Rewards(row);
    }
   return adapter.Get();
}

Thank-you


2 replies

Badge +11

You could simply call Base.Actions.PressSave() or Base.Persist() to force the record to be saved before your code runs. But your logic is based upon the assumption that Order will always be created ‘On Hold’.

I would suggest departing from that logic and instead overriding the Persist method. Since this will run every time the record is saved, you can check the status of the Order to see if it was just inserted.

Something like:

public delegate void PersistDelegate();
[PXOverride]
public void Persist(PersistDelegate baseMethod)
{
var order = Base.Document.Current;
bool inserted = Base.Document.Cache.GetStatus(order) == PXEntryStatus.Inserted;

baseMethod();

if (inserted)
{
// Your code here
}
}

 

Userlevel 2
Badge

We have our default set to start the order on hold.  In our business we get very large orders, i.e. 100 lines or more, that often repeat items.  Our customers are businesses that are ordering for their specific customers.  One of the things we do when remove hold is done is combine like order lines so an item is only printed on the pack list once with the total quantity.  That can all be done in cache.

Our users also tend to press save along the way when entering the large orders and I have to wait until the order is completely entered to check for rewards so they method you suggested above will not work for us.

 

The following code does get me the order number, but gives me the Remove Hold Button has been disabled error.  When I had the BaseMethod(adapter) line before my code I get an error that the data has been updated by another process.

Base.Persist();
SOOrder row = Base.Document.Current;
if (row != null)
{
    RewardView.Current.RewardAction = false;
    Rewards(row);
}
BaseMethod(adapter);
return adapter.Get();

 

Any other ideas that I can try?  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