Update incorrect purchase order status

In case you see that the purchase order header or line status is wrong you can run a script that updates the line status based on the remaining qty and the header status based on the lowest status used in the purchase order lines.

static void updatePOStatus(Args _args)
{
    Purchtable 		purchtable;
    PurchStatus 	oldPurchStatus;

    while select forUpdate purchtable
        where purchtable.PurchStatus == PurchStatus::Backorder
    {
        oldPurchStatus = purchtable.Purchstatus;
        purchtable.updateBackStatus();
        if (Purchtable.PurchStatus != oldPurchStatus)
        {
            info(strfmt("PO %1 updated, from %2 to %3",purchtable.PurchId, oldPurchStatus, Purchtable.PurchStatus));
        }
    }
}

OR

static void updatePOLineStatus(Args _args)
{
    Purchline       purchline;
    PurchStatus     oldPurchStatus;

    while select forUpdate purchline
        where purchline.PurchStatus == PurchStatus::Backorder
    {
        oldPurchStatus = purchline.Purchstatus;
        purchline.setPurchStatus(true);
        if (purchline.PurchStatus != oldPurchStatus)
        {
            info(strfmt('PO %1 updated, from %2 to %3',purchline.PurchId, oldPurchStatus, purchline.PurchStatus));
        }
    }
}
Advertisements