Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Answered

How to Add the record in Item Table with template?

Posted on by 2,201 Moderator

So, I have created my "custom template" and selected that template in my set parameter form, now the requirement is to create the item only giving the description as input, and all the other fields should not be visible to the user and populate from my "service template" that I have set in my set parameter form.

I have created the template and I can fetch my "custom template" data...

procedure txtDefault()
    var
        CreateItem: Record Item;
        ItemTempl: Record "Item Templ.";
        setupTable: Record myParameterTable;

    begin
        ItemTempl.reset;
        setupTable.Get();
        ItemTempl.Code := setupTable.ItemTemplate;
        if ItemTempl.Find('=') then begin
            CreateItem.Init();
            CreateItem."Base Unit of Measure" := ItemTempl."Base Unit of Measure";
            CreateItem."Price Unit Conversion" := ItemTempl."Price Unit Conversion";
            CreateItem.Type := ItemTempl.Type;
            CreateItem."Inventory Posting Group" := ItemTempl."Inventory Posting Group";
            CreateItem."Shelf No." := ItemTempl."Shelf No.";
            CreateItem."Item Disc. Group" := ItemTempl."Item Disc. Group";
            CreateItem."Allow Invoice Disc." := ItemTempl."Allow Invoice Disc.";
            CreateItem."Statistics Group" := ItemTempl."Statistics Group";
            CreateItem."Commission Group" := ItemTempl."Commission Group";
            CreateItem."Unit Price" := ItemTempl."Unit Price";
            CreateItem."Price/Profit Calculation" := ItemTempl."Price/Profit Calculation";
            CreateItem."Profit %" := ItemTempl."Profit %";
            CreateItem."Costing Method" := ItemTempl."Costing Method";
            CreateItem."Unit Cost" := ItemTempl."Unit Cost";
            CreateItem."Standard Cost" := ItemTempl."Standard Cost";
            CreateItem."Indirect Cost %" := ItemTempl."Indirect Cost %";
            CreateItem."Vendor No." := ItemTempl."Vendor No.";
            CreateItem."Vendor Item No." := ItemTempl."Vendor Item No.";
            CreateItem."Lead Time Calculation" := ItemTempl."Lead Time Calculation";
            CreateItem."Reorder Point" := ItemTempl."Reorder Point";
            CreateItem."Maximum Inventory" := ItemTempl."Maximum Inventory";
            CreateItem."Reorder Quantity" := ItemTempl."Reorder Quantity";
            CreateItem."Unit List Price" := ItemTempl."Unit List Price";
            CreateItem."Duty Due %" := ItemTempl."Duty Due %";
            CreateItem."Duty Code" := ItemTempl."Duty Code";
            CreateItem."Gross Weight" := ItemTempl."Gross Weight";
            CreateItem."Net Weight" := ItemTempl."Net Weight";
            CreateItem."Units per Parcel" := ItemTempl."Units per Parcel";
            CreateItem."Unit Volume" := ItemTempl."Unit Volume";
            CreateItem.Durability := ItemTempl.Durability;
            CreateItem."Freight Type" := ItemTempl."Freight Type";
            CreateItem."Tariff No." := ItemTempl."Tariff No.";
            CreateItem."Duty Unit Conversion" := ItemTempl."Duty Unit Conversion";
            CreateItem."Country/Region Purchased Code" := ItemTempl."Country/Region Purchased Code";
            CreateItem."Budget Quantity" := ItemTempl."Budget Quantity";
            CreateItem."Budgeted Amount" := ItemTempl."Budgeted Amount";
            CreateItem."Budget Profit" := ItemTempl."Budget Profit";
            CreateItem.Blocked := ItemTempl.Blocked;
            CreateItem."Block Reason" := ItemTempl."Block Reason";
            CreateItem."Price Includes VAT" := ItemTempl."Price Includes VAT";
            CreateItem."VAT Bus. Posting Gr. (Price)" := ItemTempl."VAT Bus. Posting Gr. (Price)";
            CreateItem."Gen. Prod. Posting Group" := ItemTempl."Gen. Prod. Posting Group";
            CreateItem."Country/Region of Origin Code" := ItemTempl."Country/Region of Origin Code";
            CreateItem."Automatic Ext. Texts" := ItemTempl."Automatic Ext. Texts";
            CreateItem."Tax Group Code" := ItemTempl."Tax Group Code";
            CreateItem."VAT Prod. Posting Group" := ItemTempl."VAT Prod. Posting Group";
            CreateItem.Reserve := ItemTempl.Reserve;
            CreateItem."Global Dimension 1 Code" := ItemTempl."Global Dimension 1 Code";
            CreateItem."Global Dimension 2 Code" := ItemTempl."Global Dimension 2 Code";
            CreateItem."Stockout Warning" := ItemTempl."Stockout Warning";
            CreateItem."Prevent Negative Inventory" := ItemTempl."Prevent Negative Inventory";
            CreateItem."Item Category Code" := ItemTempl."Item Category Code";
            CreateItem."Manufacturing Policy" := ItemTempl."Manufacturing Policy";
            CreateItem."Reordering Policy" := ItemTempl."Reordering Policy";
            CreateItem."Item Tracking Code" := ItemTempl."Item Tracking Code";
            CreateItem."Lot Nos." := ItemTempl."Lot Nos.";
            CreateItem."Serial Nos." := ItemTempl."Serial Nos.";
            CreateItem."Warehouse Class Code" := ItemTempl."Warehouse Class Code";
            CreateItem."Special Equipment Code" := ItemTempl."Special Equipment Code";
            CreateItem."Put-away Template Code" := ItemTempl."Put-away Template Code";
            CreateItem.Description := 'Description Final Testing two';
            CreateItem.Insert(true);
            Message('Item Added');
        end;

But the problem is that I have to map all the fields from my template, I'm not sure If I'm doing it right, is there any other shortcut way like using the system's code unit procedure instead of writing all it down? I've tried debugging the process but couldn't find which procedure of CodeUnit "Item Templ. Mgt." to use? can you guys help me find out? Also, the above way is working fine.. what should I do?

  • Govinda Kumar Profile Picture
    Govinda Kumar 2,201 Moderator on at
    RE: How to Add the record in Item Table with template?

    Dear YUN ZHU

    Thank you

    First inserting the item record, with No. and Description, and then applying the template with the ApplyItemTemplate procedure is working great.. this is what I was looking for.. thanks for helping.

    Regards.

  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 69,864 Super User 2024 Season 2 on at
    RE: How to Add the record in Item Table with template?

    Hi, I think you can insert an Item with only No. first, and then run Apply Template. If you don't want any action on the UI, you can look into the following code.

    pastedimage1663721042049v1.png

    pastedimage1663721054351v2.png

    pastedimage1663721096664v3.png

    pastedimage1663721123126v4.png

    pastedimage1663721165551v5.png

    Hope this helps.

    Thanks.

    ZHU

  • Suggested answer
    Amit Baru Profile Picture
    Amit Baru 3,025 on at
    RE: How to Add the record in Item Table with template?

    Hi 

    code is right. Add 

    CreateItem."No" := From No. series. I think this missing in your code. This is primary key and it is mandatory for creating Item

    Regards

    Amit Sharma

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,552 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,552 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans