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 :
Small and medium business | Business Central, N...
Suggested Answer

Create Pick According to Bin Ranking

(0) ShareShare
ReportReport
Posted on by 47

I have got a task that when we press Create Pick in the Warehouse Shipment the process will be that we must pick according to Expiration date then if we have the Item in 2 different bin we must get the one with higher ranking before looking at the lot No. or Package No. 

The Code I Wrote

 [EventSubscriber(ObjectType::Codeunit, 7312, 'OnBeforeTempWhseActivLineInsert', '', false, false)]
    local procedure FillRBinCode(var TempWarehouseActivityLine: Record "Warehouse Activity Line"; ActionType: Integer)
    var
        WarEntry: Record "Warehouse Entry";
        i: Integer;
        BinList: List of [Code[20]];
        RankingList: List of [Integer];
        BinContent: Record "Bin Content";
        HighestBinRanking: Integer;
        IndexOfHBR: Integer;
        TempBinContent: Record "Bin Content";
        ArrLength: Integer;
        QuantityTempWhseActivityLine: Decimal;
        TempWhseActLine: Record "Xee_Temporary Whse Pick Lines";
        TempWhseActLineF: Record "Xee_Temporary Whse Pick Lines";
        TotalQty: Decimal;

    begin
           
         
           
        if ActionType = TempWarehouseActivityLine."Action Type"::Take.AsInteger() then begin
           

            WarEntry.SetCurrentKey("Location Code", "Item No.", "Lot No.", "Bin Type Code");
            WarEntry.SetRange("Location Code", TempWarehouseActivityLine."Location Code");
            WarEntry.SetRange("Item No.", TempWarehouseActivityLine."Item No.");
            WarEntry.SetRange("Lot No.", TempWarehouseActivityLine."Lot No.");
            WarEntry.SetRange("Package No.", TempWarehouseActivityLine."Package No.");
           
            WarEntry.SetFilter(Quantity, '>0');
            WarEntry.SetRange("Bin Type Code", 'PUTPICK');


            if WarEntry.FindFirst() then
                repeat


                   
                    BinContent.SetFilter("Location Code", TempWarehouseActivityLine."Location Code");
                    BinContent.SetFilter("Bin Code", WarEntry."Bin Code");
                    BinContent.SetFilter("Item No.", WarEntry."Item No.");
                    BinContent.SetFilter("Variant Code", TempWarehouseActivityLine."Variant Code");

                   
                    if BinContent.FindFirst() then
                        repeat
                        BinContent.CalcFields("Pick Qty.", Quantity, "Pick Quantity (Base)","Quantity (Base)");
                        if BinContent."Quantity (Base)" < TempWarehouseActivityLine."Qty. (Base)" then
                            begin
                               
                                Error(Error_XeeZ);
                            end;
                           
                            TotalQty := 0;
                            TempWhseActLineF.Reset();
                            TempWhseActLineF.SetFilter("Item No.", BinContent."Item No.");
                            TempWhseActLineF.SetRange("Bin Code", BinContent."Bin Code");
                            TempWhseActLineF.SetRange("Lot No.", TempWarehouseActivityLine."Lot No.");
                            TempWhseActLineF.SetRange("Package No.", TempWarehouseActivityLine."Package No.");
                            if TempWhseActLineF.FindLast() then;
                            if not (BinList.Contains(WarEntry."Bin Code")) and (TotalQty <> BinContent."Quantity (Base)")
                            then begin
                                   
                                BinList.Add(WarEntry."Bin Code");
                                RankingList.Add(BinContent."Bin Ranking");
                            end;
                        until BinContent.Next() = 0;

                until WarEntry.next = 0;

            HighestBinRanking := 0;
            for i := 1 to RankingList.Count do begin
                if RankingList.Get(i) > HighestBinRanking then begin
                    HighestBinRanking := RankingList.Get(i);
                    IndexOfHBR := i;
                end;
            end;




            if IndexOfHBR <> 0 then begin

                TempBinContent.SetFilter("Location Code", TempWarehouseActivityLine."Location Code");
                TempBinContent.SetFilter("Bin Code", BinList.Get(IndexOfHBR));
                TempBinContent.SetFilter("Item No.", WarEntry."Item No.");
                TempBinContent.SetFilter("Variant Code", TempWarehouseActivityLine."Variant Code");
                if TempBinContent.FindFirst() then begin

                    TempWarehouseActivityLine."Bin Code" := TempBinContent."Bin Code";
                    TempWarehouseActivityLine."Zone Code" := BinContent."Zone Code";
                    TempWarehouseActivityLine."Bin Ranking" := BinContent."Bin Ranking";
                    

                 
             
                end;
            end;




        end;
    end;
this code works when I have same expiration date and same Lot No., If I have same expiration but different Lot. No. the system will neglect the Bin Ranking and chooses to the smallest Lot No.
I have the same question (0)
  • Suggested answer
    Andy Sather Profile Picture
    on at
    RE: Create Pick According to Bin Ranking

    Hello  - We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    I will open this up to the community in case they have something to add.

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,421

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,878 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,645 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans