Skip to main content

Notifications

Announcements

No record found.

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.
  • Suggested answer
    Andy Sather Profile Picture
    Andy Sather 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

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans