web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Suggested answer

How to cancel a product receipt for a Consignment Replenishment Order in Dynamics 365 Finance and Operations (D365FO) using X++

(0) ShareShare
ReportReport
Posted on by 15

How to cancel a product receipt for a Consignment Replenishment Order in Dynamics 365 Finance and Operations (D365FO) using X++

I have the same question (0)
  • Suggested answer
    Siv Sagar Profile Picture
    4,236 Super User 2025 Season 2 on at
    RE: How to cancel a product receipt for a Consignment Replenishment Order in Dynamics 365 Finance and Operations (D365FO) using X++

    Hi Javid,

    To cancel a product receipt for a Consignment Replenishment Order in Dynamics 365 Finance and Operations (D365FO) using X++, you can follow these steps:

    Open the development environment (Visual Studio).

    Create a new job or open an existing job.

    Connect to the D365FO environment and select the appropriate company.

    Write the X++ code to cancel the product receipt. Here's an example:

    static void CancelProductReceipt(Args _args)

    {

       InventTrans inventTrans;

       InventTransRefType inventTransRefType;

       VendPackingSlipJour vendPackingSlipJour;

       VendPackingSlipLine vendPackingSlipLine;

       InventTransId inventTransId = '<your_inventtrans_id>';

       // Retrieve the inventory transaction for the consignment replenishment order

       select inventTrans

           where inventTrans.TransRefId == inventTransId &&

                 inventTrans.RefTransRefId != '';

       while (inventTrans)

       {

           // Retrieve the reference type for the inventory transaction

           inventTransRefType = inventTrans.getTransRefType();

           // Check if the reference type is a packing slip

           if (inventTransRefType == InventTransRefType::PackingSlip)

           {

               // Retrieve the packing slip journal based on the reference id

               vendPackingSlipJour = VendPackingSlipJour::find(inventTrans.RefTransRefId);

               // Cancel the packing slip journal

               if (vendPackingSlipJour)

               {

                   vendPackingSlipJour.packingSlipStatus = VendPackingSlipStatus::Canceled;

                   vendPackingSlipJour.update();

                   // Retrieve the packing slip lines and cancel them

                   while select forUpdate vendPackingSlipLine

                       where vendPackingSlipLine.PackingSlipId == vendPackingSlipJour.PackingSlipId

                   {

                       vendPackingSlipLine.LineStatus = VendPackingSlipLineStatus::Canceled;

                       vendPackingSlipLine.update();

                   }

               }

           }

           // Move to the next inventory transaction

           inventTrans = inventTrans.next();

       }

       info("Product receipt canceled successfully.");

    }

    Replace <your_inventtrans_id> with the actual InventTransId of the consignment replenishment order you want to cancel.

    Compile and run the job.

    The code will search for the specified consignment replenishment order's inventory transactions and check if they reference a packing slip. If a packing slip is found, it will be canceled, along with its associated packing slip lines.

    After running the job, you should see a confirmation message stating that the product receipt was canceled successfully.

    Please note that this code is a basic example and may need modification based on your specific requirements and customization in your D365FO environment.

  • Javidcse Profile Picture
    15 on at
    RE: How to cancel a product receipt for a Consignment Replenishment Order in Dynamics 365 Finance and Operations (D365FO) using X++

    Copy Paste from ChatGPT. even replenishment order journal records not going to vendPackingSlipJour and trans.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 900

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 256 Super User 2025 Season 2

#3
Sagar Suman Profile Picture

Sagar Suman 188 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans