Update incorrect Sales order status

In case you see that the sales 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 sales order lines.

static void updateSOLineStatus(Args _args)
{
    SalesLine       salesLine;
    SalesStatus     oldSalesStatus;

    while select forUpdate salesLine
        where salesLine.SalesStatus == SalesStatus::Backorder
    {
        oldSalesStatus = salesLine.SalesStatus;
        salesline.setSalesStatus();
        ttsBegin;
        salesLine.update();
        ttsCommit;
        if (salesLine.SalesStatus != oldSalesStatus)
        {
            info(strfmt('SO %1 updated, from %2 to %3',salesLine.SalesId, oldSalesStatus, salesLine.SalesStatus));
        }
    }
}
Advertisements

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));
        }
    }
}