Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

How to get the reservation of sales line

Posted on by 559

Hi Experts,

Does anyone know how to get the reservation of sales line through X++, like inventory location, batch and quantity?

Thanks.

  • HenryXie Profile Picture
    HenryXie on at
    RE: How to get the reservation of sales line

    hi,

    this code can work in AX3.0 for your reference. 

    public static server void Svc_SalesLineReservation(RecId _recId
                                                        , InventDimId _dimId
                                                        , Qty _qty ,date _date = systemdateget())
            {
                InventTrans             l_invTrans;
                SalesLine               l_salesLine;
                InventMovement          l_inventMovement;
                InventUpd_Reservation   l_inventUpd_Reservation ;
                InventDim               l_invDim;
                SalesLine               l_line;
                InventSum               l_sum;
                ;
                 systemdateset(_date);
                try
                {
                    l_invDim = InventDim::find(_dimId);
           
                    ttsbegin;
                    l_line = SalesLine::findRecId(_recId,true);
                    if(!l_line.RecId)
                    {
                         throw error(strFmt("Can not find the line recID : %1",_recId));
                    }
                    l_sum = InventSum::find(l_line.ItemId,_dimId);
                    if(l_sum.AvailPhysical < _qty)
                    {
                          throw error(strFmt("There is not enough inventory onhand quantity (%8) for delivery (%9). SalesOrder : %1 ; LineNum : %2 ; Warehouse: %3 ; Location: %4 ; Batch: %5 ; Pallet: %6; Serial: %7 ;"
                            ,l_line.SalesId,l_line.LineNum,l_invDim.InventLocationId,l_invDim.wMSLocationId,l_invDim.inventBatchId,l_invDim.wMSPalletId,l_invDim.inventSerialId
                            ,l_sum.AvailPhysical,_qty));
                    }
                    l_line.RemainInventPhysical  = UnitConvert::qty(l_line.RemainSalesPhysical,
                                                         l_line.salesUnit,
                                                         l_line.inventTable().inventUnitId(),
                                                         l_line.itemId);
                    if(l_line.RemainInventPhysical < l_line.InventDeliverNow + _qty)
                    {
                        l_line.RemainInventPhysical = l_line.InventDeliverNow + _qty;
                        l_line.RemainSalesPhysical = UnitConvert::qty(l_line.RemainInventPhysical,
                                                         l_line.inventTable().inventUnitId(),
                                                         l_line.salesUnit,
                                                         l_line.itemId);
                    }
                    l_line.InventDeliverNow = l_line.InventDeliverNow + _qty;
                    l_line.SalesDeliverNow = UnitConvert::qty(l_line.InventDeliverNow,
                                                         l_line.inventTable().inventUnitId(),
                                                         l_line.salesUnit,
                                                         l_line.itemId);
                    l_line.update();
                    ttscommit;
                    l_inventMovement = InventMovement::construct(l_line);
                    l_inventUpd_Reservation =
                        InventUpd_Reservation::newInventDim(
                                    l_inventMovement
                                    ,l_invDim
                                    ,_qty * -1
                                );
                    l_inventUpd_Reservation.updatenow();
                        }
                catch (Exception::Deadlock)
                {
                    retry;
                }
            }

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,253 Super User 2024 Season 2 on at
    RE: How to get the reservation of sales line

    Hi Bernardqin,

    This is not something we have to use daily. So I can't help you directly. You can have a look at the reservation form what logic is used to show the reservations. So, with some reverse engineering, you should be able to find out what x++ logic needs to be used to achieve your requirement.

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans