Monday, September 1, 2025

Cancel purch order all quantity using x++ D365fo

 PurchTable          purchTableLoc;

PurchLine           purchLineLoc;

InventTrans         inventTransLoc;

InventTransOrigin   inventTransOriginLoc;

ttsBegin;

purchTableLoc = PurchTable::find(_purchId, true);

if (purchTable != null)

{                    

    while select forupdate * from purchLineLoc

        where purchLineLoc.PurchId     == purchTableLoc.PurchId

           && purchLineLoc.PurchStatus == PurchStatus::Backorder

    join  inventTransLoc

    exists join inventTransOriginLoc

        where inventTransOriginLoc.RecId         ==  inventTransLoc.InventTransOrigin

           && inventTransOriginLoc.InventTransId == purchLineLoc.InventTransId

    {

  // to check the purch lines are not received

        if(inventTrans.StatusReceipt == StatusReceipt::Ordered)

        {

            purchLineLoc.RemainInventPhysical = 0.00;

            purchLineLoc.RemainPurchPhysical  = 0.00;

            purchLineLoc.reread();

            purchLineLoc.update();

            InventMovement::bufferSetRemainQty(purchLineLoc);

        }

    }

    purchTableLoc.PurchStatus = PurchStatus::Canceled;

    purchTableLoc.update();

}

ttsCommit;

Call API using x++ D365FO

 System.Net.HttpWebRequest    request; System.Net.HttpWebResponse   response; System.IO.Stream             dataStream; System.IO.StreamReade...