Put Document on Hold with Code

Hi All

May Acumatica documents have an imbedded workflow. Hold/Unhold is usually a part of this worflow.
Sometimes we may want to emulate user behavior thought the code, but there is a trick here.

Acumatica’s Hold checkbox usually adds a hidden button that is triggered automatically when you check/uncheck hold. When you work thought the code you need to consider it and call button as well.

Here is example on how to call hold on Purchase Order:

public PXAction<POOrder> PutOnHold;
[PXButton()]
[PXUIField(DisplayName = "Put On Hold")]
public void putOnHold()
{
    POOrder row = Base.Document.Current;
    if (row != null)
    {
        //row.Status = POOrderStatus.Hold;
        row.Hold = true;
        row = Base.Document.Update(row);

        Base.hold.Press();
    }
}

public PXAction<POOrder> Submit;
[PXButton()]
[PXUIField(DisplayName = "Submit")]
public void submit()
{
    POOrder row = Base.Document.Current;
    if (row != null)
    {
        //row.Status = POOrderStatus.Open;
        row.Hold = false;
        row = Base.Document.Update(row);

        Base.hold.Press();
    }
}

Hope it helps and have a nice development!

Leave a Reply

Please rate*

Your email address will not be published. Required fields are marked *