Skip to main content

Notifications

Microsoft Dynamics AX (Archived)
Under review by Community Managers

Under review

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

How to Reserve Lot Picking list registration for All Lines in D365 using X++

Posted on by 6

Hi Experts,

on WMSPickingRegistration form to set Resolve Lot Easly for my company user as Donky work and Wasted a lot of time,
As we all know Resolve lot for Selected Line in D365 as be as shown in the attached pictures as well,

01

Image

02

Image

03

Image

So that I want to add Customize on the above form WMSPickingRegistration on No. 5 in the above image also to Resolve Lot for all Lines to consume Donky work and Wasted a lot of time.

So I Implemented the Attached Code Class to involve that but I have iusse and I don't understand where?

Some links to help:
community.dynamics.com/.../reserve-salesline-throughcode
www.schweda.net/blog_ax.php
sangeethwiki.blogspot.com/.../reserve-and-unreserve-sales-order-line.html
www.instructorbrandon.com/.../
www.dynamicsuser.net/.../7
community.dynamics.com/.../x-to-update-sales-line-reserve-physical-qty
gfeaxblog.wordpress.com/.../
eurom.be/.../storage-dimension-group-in-d365.html
axfactory.wordpress.com/.../
https://timsaxblog.wordpress.com/2015/08/31/the-reserved-ordered-items-inventory-parameter/

Code:

public class GOWMSPickingRegistrationReserveLot

{

   WMSOrderTrans   _WMSOrderTrans , _WMSOrderTransInsert;

   InventMovement _InventMovement;

   InventUpd_Reservation   _InventUpd_Reservation;

   InventSum               _InventSum;

   InventBatch     inventBatch;

   InventDim               inventDim;

   Qty         totalReservedQty,mainQty ,availableQty, RemainQty;

   public void ReserveLotLine(RecId _wmsOrderTransRecId)

   {

       select forUpdate _WMSOrderTrans

           where _WMSOrderTrans.RecId == _wmsOrderTransRecId;

       //select _InventSum

       //where  _InventSum.InventDimId == _WMSOrderTrans.inventDimId &&

       //       _InventSum.ItemId == _WMSOrderTrans.itemId

       select  _InventSum

           where  _InventSum.ItemId == _WMSOrderTrans.itemId &&//'F000442' &&

           _InventSum.AvailPhysical != 0

           join   inventBatch

                   order by inventBatch.expDate desc

           where  inventBatch.inventBatchId == _InventSum.inventBatchId

           join   inventDim

           where  inventDim.inventDimId == _InventSum.inventDimId;

       availableQty = _InventSum.AvailPhysical;// physicalInventCalculated(); //345+48 = 393

       //confirm -QTYs

       if (availableQty >= _WMSOrderTrans.qty)

       {

           this.UpdateLineNow(_WMSOrderTrans);

       }

       else

       {

           mainQty = _WMSOrderTrans.qty; // 102

           RemainQty = availableQty - mainQty; //393 - 102 = 291

           select _InventSum

           where  _InventSum.PostedQty + _InventSum.Received - _InventSum.Deducted + _InventSum.Registered - _InventSum.Picked >= RemainQty

           && _InventSum.ItemId == _WMSOrderTrans.itemId;

           //Order by InventBatch Expired date && Big on-Hand

           if(_InventSum)

           {

               ttsBegin;

               _WMSOrderTrans.qty = availableQty;

               _WMSOrderTrans.update();

               ttsCommit;

               this.UpdateLineNow(_WMSOrderTrans);

               //insert New Row///

               _WMSOrderTransInsert.data(_WMSOrderTrans);

               _WMSOrderTransInsert.inventDimId = _InventSum.InventDimId;

               _WMSOrderTransInsert.qty = RemainQty;

               _WMSOrderTransInsert.IsReserved = NoYes::Yes;

               _WMSOrderTransInsert.expeditionStatus = WMSExpeditionStatus::Complete;

               _WMSOrderTransInsert.insert();

               this.UpdateLineNow(_WMSOrderTransInsert);

           }

           else

           {

               //info("there is no onhand for all Qty")

               ttsBegin;

               _WMSOrderTrans.qty = availableQty;

               _WMSOrderTrans.update();

               ttsCommit;

               this.UpdateLineNow(_WMSOrderTrans);

               totalReservedQty += availableQty;

               if(mainQty > totalReservedQty)

               this.UpdateLineRecursiveNow(mainQty-totalReservedQty);

           }

       }

   }

   //////////////////////////////////////////////////////

   private void UpdateLineNow(WMSOrderTrans currWMSOrderLine)

   {

       if(_WMSOrderTrans)

       {

           _InventMovement = _WMSOrderTrans.inventMovement(true);

           _InventUpd_Reservation = InventUpd_Reservation::newInventDim(_InventMovement,currWMSOrderLine.inventDim(),currWMSOrderLine.qty * -1,false);

           _InventUpd_Reservation.updateNow();

       }

   }

   //////////////////////////////////////////////////////

   private void UpdateLineRecursiveNow(Qty _RQty)

   {

       select _InventSum

       where  _InventSum.PostedQty + _InventSum.Received - _InventSum.Deducted + _InventSum.Registered - _InventSum.Picked >= 0

           && _InventSum.ItemId == _WMSOrderTrans.itemId;

       //Order by InventBatch Expired date && Big on-Hand

       if(_RQty < _InventSum.physicalInventCalculated())

       {

           _WMSOrderTransInsert.data(_WMSOrderTrans);

           _WMSOrderTransInsert.inventDimId = _InventSum.InventDimId;

           _WMSOrderTransInsert.qty = _RQty;

           _WMSOrderTransInsert.IsReserved = NoYes::Yes;

           _WMSOrderTransInsert.insert();

           this.UpdateLineNow(_WMSOrderTransInsert);

           totalReservedQty += availableQty;

       }

       else

       {

           _WMSOrderTransInsert.data(_WMSOrderTrans);

           _WMSOrderTransInsert.inventDimId = _InventSum.InventDimId;

           _WMSOrderTransInsert.qty = _InventSum.physicalInventCalculated();

           _WMSOrderTransInsert.IsReserved = NoYes::Yes;

           _WMSOrderTransInsert.insert();

           this.UpdateLineNow(_WMSOrderTransInsert);

           totalReservedQty += _InventSum.physicalInventCalculated();

           if(mainQty > totalReservedQty)

               this.UpdateLineRecursiveNow(mainQty-totalReservedQty);

       }

   }

   //////////////////////////////////////////////////////

}

H.R

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,902 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,297 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans