Skip to main content

Notifications

Announcements

No record found.

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++

Posted on by 15

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

  • Javidcse Profile Picture
    Javidcse 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.

  • Suggested answer
    Siv Sagar Profile Picture
    Siv Sagar 3,247 Super User 2024 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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans