Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

AL Codeunit for creating new serialized items?

Posted on by 618

So I have working AL code that hits our test BC 365 v19 W1 environment. In terms of creating new items, along with posting positive adjustments to the item journal to allocate site on-hand availability for each newly-created item. A new requirement would involve item serialization. Wondering at what point in my AL code would I instantiate the auto-assigned serial number for the items as I'm creating them. Would this take place in the positive adjustment that I'm inserting into the item journal? Haven't found any AL code examples searching online so far... 

UPDATE: Disregard, as I see now that the reservation entry for the serialized item takes place after the item journal entry commits. I can take it from here :) 

  • cbergamini Profile Picture
    cbergamini 45 on at
    RE: AL Codeunit for creating new serialized items?

    Yes, I wanted to use the Configuration Package to load both non-serialized Items and serialized items. Obviously the configuration package works fine for non-serialized items but now realized that I cannot load serialized items using the package. It looks I must have a developer add code to get it to work for serialized items.

  • Greg Kujawa Profile Picture
    Greg Kujawa 618 on at
    RE: AL Codeunit for creating new serialized items?

    If by loading serialized items you mean using the Excel sheet templates for importing, then I think those templates are just for non-serialized items. More barebones without the specificity. The way that worked for me was utilizing a AL codeunit extension to make the required reservation entry. The sample above worked, if that's a steer in the right direction.

  • cbergamini Profile Picture
    cbergamini 45 on at
    RE: AL Codeunit for creating new serialized items?

    I am looking for a way to load Serialzied Items but I see there is no way without developing code to add Item Serial Counts, correct?

  • Verified answer
    Marco Mels Profile Picture
    Marco Mels on at
    RE: AL Codeunit for creating new serialized items?

    Hi!

    No problem to use this community as well for development type of questions. It is just that Microsoft support does not answer these kind of questions. To make you aware of our yammer groups, we refer to them.

    Thank you so much for sharing the outcome! This is very helpful for the community.

  • Greg Kujawa Profile Picture
    Greg Kujawa 618 on at
    RE: AL Codeunit for creating new serialized items?

    Thanks for the info! I wasn't aware of these two other resources, as I thought that this Dynamics 365 Community area was the best place. Will check them out.

    Just for some closure, and if anyone else would be interested, below is the AL code that accomplishes what I was looking to implement. Hope it helps someone who might run across it in the future.

    procedure InsertItemJournal(ItemNo: Text; SerialNo: Text; LocationCode: Text; Qty: Integer; UnitCost: Decimal; DateIn: Text; VendorDocNo: Text; OurDocNo: Text; Descr: Text; ShortDim1Code: Text; ShortDim2Code: Text)
        var
            ItemJnl: Record "Item Journal Line";
            TempReservEntry: Record "Reservation Entry" temporary;
            Rec_ResEnt_Lu: Record "Reservation Entry";
            CreateReservEntry: Codeunit "Create Reserv. Entry";
            ReservStatus: Enum "Reservation Status";
            LineNo: Integer;
            ValDateIn: Date;
        begin
            ItemJnl.Init();
            if ItemJnl.FindLast() then
                LineNo := ItemJnl."Line No."   10000
            else
                LineNo := 10000;
            ItemJnl."Line No." := LineNo;
            ItemJnl."Entry Type" := ItemJnl."Entry Type"::"Positive Adjmt.";
            ItemJnl.Validate("Item No.", ItemNo);
            ItemJnl.Validate("Document No.", VendorDocNo);
            if OurDocNo = '' then
                ItemJnl.Validate(Description, Descr)
            else
                ItemJnl.Validate(Description, OurDocNo);
            ItemJnl.Validate("Journal Batch Name", 'DEFAULT');
            ItemJnl.Validate("Journal Template Name", 'ITEM');
            ItemJnl.Validate(Quantity, Qty);
            ItemJnl.Validate("Location Code", LocationCode);
            ItemJnl.Validate("Unit Amount", UnitCost);
            Evaluate(ValDateIn, DateIn);
            ItemJnl.Validate("Posting Date", ValDateIn);
            ItemJnl.Validate("Shortcut Dimension 1 Code", ShortDim1Code);
            ItemJnl.Validate("Shortcut Dimension 2 Code", ShortDim2Code);
            ItemJnl.Insert();
            Commit();
    
            TempReservEntry.Init();
            Rec_ResEnt_Lu.Reset();
            if Rec_ResEnt_Lu.FindLast() then
                TempReservEntry."Entry No." := Rec_ResEnt_Lu."Entry No."   1
            else
                TempReservEntry."Entry No." := 1;
    
            if SerialNo <> '' then begin
                TempReservEntry."Serial No." := SerialNo;
                TempReservEntry.Quantity := Qty;
                TempReservEntry."Expiration Date" := Today();
                TempReservEntry.Insert();
                Commit();
    
                CreateReservEntry.SetDates(0D, TempReservEntry."Expiration Date");
                CreateReservEntry.SetNewSerialLotNo(TempReservEntry."Serial No.", TempReservEntry."Lot No.");
                CreateReservEntry.CreateReservEntryFor(Database::"Item Journal Line", ItemJnl."Entry Type".AsInteger(), ItemJnl."Journal Template Name", ItemJnl."Journal Batch Name",
                    0, ItemJnl."Line No.", ItemJnl."Qty. per Unit of Measure", TempReservEntry.Quantity, TempReservEntry.Quantity * ItemJnl."Qty. per Unit of Measure", TempReservEntry);
                CreateReservEntry.CreateEntry(ItemJnl."Item No.", ItemJnl."Variant Code", ItemJnl."Location Code", '', 0D, 0D, 0, ReservStatus::Surplus);
            end;
        end;

  • Suggested answer
    Marco Mels Profile Picture
    Marco Mels on at
    RE: AL Codeunit for creating new serialized items?

    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

    dynamicsuser.net/.../developers

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

    Thanks.

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans