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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s