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

AL Codeunit for creating new serialized items?

(0) ShareShare
ReportReport
Posted on by 583

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 :) 

I have the same question (0)
  • Suggested answer
    Marco Mels Profile Picture
    on at

    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.

  • Greg Kujawa Profile Picture
    583 on at

    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;

  • Verified answer
    Marco Mels Profile Picture
    on at

    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.

  • cbergamini Profile Picture
    45 on at

    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?

  • Greg Kujawa Profile Picture
    583 on at

    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
    45 on at

    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.

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 2,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans