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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Inventory always reserving from Pack even after customisation on InventUpd_Reservation.

(1) ShareShare
ReportReport
Posted on by 87

Hi Experts,

I am facing an issue in D365 Finance & Operations (Supply Chain – Inventory Reservation) where the reservation behaves differently across forms. As I want to reserve inventory not from the Pack location (Which I put under parameter) while Creating BOM Journal from Reported as finished. 

Current Behavior

I reserve inventory programmatically using InventUpd_Reservation.

Reservation shows correctly in:

     InventTrans
     BOM Reservation form

However, in InventOnhandItem, the reservation still appears against the PACK WMS location, even though:

I programmatically change the InventDimId to a different valid WMS location with stock.

So effectively:

InventTrans & BOM → show reservation from the correct location

InventOnhandItem → still shows reservation from PACK location (I dont want to reseve items from the Pack location


 

What I am trying to achieve

Yet InventSum (On-hand) still keeps the reservation under the old PACK dimension.

PACK location should NEVER hold reservation

Reservation should always move to another valid WMS location with available physical stock

All 3 places must be in sync:

       InventTrans

       BOM Reservation

       InventOnhandItem

Below is the code snippet; Please help me guys 
 

[ExtensionOf(tableStr(InventJournalTrans))]
internal final class ZInventJournalTrans_Extension
{
    public void insert(NoYes _dropEstimated)
    {
        next insert(_dropEstimated);
        InventJournalTable inventJournalTable = InventJournalTable::find(this.JournalId);
        if(inventJournalTable.RecId)
        {
            InventTrans             inventTrans;
            InventTransOrigin       inventTransOrigin;
            InventMovement          inventMovement;
            InventUpd_Reservation   inventUpd_Reservation ;
            InventDim               inventDim,inventDimJoin;
            inventSum               inventSum,inventSumVal ;
            ZCustParameters         zCustParameters = ZCustParameters::find();
            str                     location;
            container               locationContainer;
            real                    ActualAvailableQty;
            int                     i ;
            Microsoft.Dynamics.Ax.Xpp.ErrorException xppEx;
            try
            {
                location = zCustParameters::find().wmsLocationId;
                locationContainer = str2con(location,';');
 
                //// Reserve an item
                select inventTransOrigin
                        where inventTransOrigin.InventTransId == this.InventTransId
                            join inventTrans
                        where inventTrans.InventTransOrigin == inventTransOrigin.RecId
                        &&  inventTrans.StatusReceipt == StatusReceipt::None ;
                select sum(AvailPhysical) from inventSum
                    where inventSum.ItemId == this.ItemId
                    &&    inventSum.InventLocationId == this.inventDim().InventLocationId;
                    //&&    inventSum.wMSLocationId != 'Pack';
                ActualAvailableQty = inventSum.AvailPhysical ;
                for(i=1 ;i<=conLen(locationContainer);i++)
                {
                    InventSum           inventSumloc;
                    str                 wmslocationIdLoc;
                    wmslocationIdLoc = conPeek(locationContainer,i);
                    select sum(AvailPhysical) from inventSumloc
                        where inventSumloc.ItemId == this.ItemId
                            &&    inventSumloc.InventLocationId == this.inventDim().InventLocationId
                            &&    inventSumloc.wMSLocationId == wmslocationIdLoc;
                            //&&    inventSumloc.wMSLocationId != 'Pack';
                    ActualAvailableQty -= inventSumloc.AvailPhysical ;
                }
                if (inventTrans.RecId )//&& ActualAvailableQty > 0)
                {
                    if (conFind(locationContainer, inventDim::find(inventTrans.inventDimId).wMSLocationId) > 0) //|| inventDim::find(inventTrans.inventDimId).wMSLocationId == 'Pack')
                    {
                        inventTrans.selectForUpdate(true);
                        ttsbegin;
                        // Find new InventDim with stock >0 and not pack
                        select sum(AvailPhysical), InventDimId, wmsLocationId
                        from inventSumVal
                        group by inventSumVal.wMSLocationId, inventSumVal.inventDimId
                        where inventSumVal.ItemId == inventTrans.ItemId
                        && inventSumVal.AvailPhysical > 0
                        //&& inventSumVal.wMSLocationId != 'Pack'
                        && inventSumVal.InventDimId != inventTrans.InventDimId;
                        if (inventSumVal.InventDimId)
                        {
                            inventTrans.InventDimId = inventSumVal.InventDimId;
                            inventTrans.doUpdate();
                        }
                        ttscommit;
                    }
                    if (ActualAvailableQty < -inventTrans.Qty)
                    {
                        inventMovement = inventTrans.inventMovement(true);
                        inventUpd_Reservation = InventUpd_Reservation::newInventDim(
                                                inventMovement,
                                                inventTrans.inventDim(),
                                                -ActualAvailableQty,
                                                false);
                        inventUpd_Reservation.updateNow();
                    }
                    else
                    {
                        inventMovement = inventTrans.inventMovement(true);
                        inventUpd_Reservation = InventUpd_Reservation::newInventDim(
                                                inventMovement,
                                                inventTrans.inventDim(),
                                                inventTrans.Qty,
                                                false);
                        inventUpd_Reservation.updateNow();
                    }
                }
              
            }
            
            catch (xppEx)
            {
                warning(strFmt("Error Occurred for Journal Id - %1 and Item id - %2", this.JournalId, this.ItemId));
                warning(xppEx.Message);
            }
            catch (Exception::Deadlock)
            {
                warning(strFmt("Error Occurred for Journal Id - %1 and Item id - %2", this.JournalId, this.ItemId));
            }
            catch (Exception::Warning)
            {
                CLRInterop::getLastException();
            }
            catch (Exception::CLRError)
            {
                CLRInterop::getLastException();
            }
        }
        
    }
 
  • Example Screenshots :

  •  
I have the same question (1)
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    300,743 Super User 2025 Season 2 on at
    Hi harshil9898.
     
    You did one thing that you should not do in coding: Updating the InventDimId of the InventTrans record directly. This can cause a lot of issues in the application. You can even corrupt the costing for the item.
     
    I don't have time to validate all logic of the code you shared, but you have an extension on the insert method of an InventJournalTrans record. This record has a settings for the inventory transactions via an InventDimId. This is the ID that will be used for the InventTrans records as well. This is managed via InventUpd classes in the application. These classes not only takes care of the InventTransOriging and InventTrans records, but also InventSum, the source for the inventory on hand information.

    When you change the InventDimId on the InventTrans with a doupdate() call, the InventSum will not be updated and some other important logic is skipped. You also have inconsistency between the InventJournalTrans record and InventTrans.  You also didn't check if the InventJournalTrans record was coming from a production order or not. The table is used for more types of inventory updates.

    Your current coding is a guanrantee for a disaster. Please change your mindset. Understand the architecure first. Ensure the correct value will be present on the InventJournalTrans record, and let the standard F&O inventory update and reservation classes do the updates to the inventory related transaction tables. If you need more guidance, then please tell more about your process and the functional requirements. 

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 687 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 403 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans