Item template configuration

Hello
for importing list from excel (create item and update existing item) how can apply item configuration template for new item in c/al ou al

Thank you

Best Answer

  • Developer101Developer101 Member Posts: 552
    Answer ✓
    Not a problem.
    You can have one template code at a time to create an Item. You have to know which one to use. Maybe store this code in your table, for example, in a field ConfigurationTemplateCode

    Then your code will be something like this :

    if mytable.findset then
    repeat

    ConfigurationHeader.RESET;
    ConfigurationHeader.SETRANGE(Code,mytable.ConfigurationTemplateCode);
    ConfigurationHeader.FINDFIRST;
    ItemTemplate.InsertItemFromTemplate(ConfigurationHeader,Item);

    until mytable.next = 0;
    United Kingdom

Answers

  • Developer101Developer101 Member Posts: 552
    you can specify configuration template as part of configuration package (Rapid start) import.
    United Kingdom
  • souoiksouoik Member Posts: 128
    @Developer101 non i need to use when validate create new item , i create à table whosh à storage my importer item liste
  • Developer101Developer101 Member Posts: 552
    What version of NAV you are using? There are some standard functions you could use to create an item using a configuration template
    United Kingdom
  • souoiksouoik Member Posts: 128
    @Developer101 Business central latest version on al code
  • Developer101Developer101 Member Posts: 552
    You could do something like this

    ItemTemplate: Record "Item Template";
    Item: Record Item;
    ConfigurationHeader: Record "Config. Template Header";

    ConfigurationHeader.RESET;
    ConfigurationHeader.SETRANGE(Code,'ITEM000001');
    ConfigurationHeader.FINDFIRST;
    ItemTemplate.InsertItemFromTemplate(ConfigurationHeader,Item);
    United Kingdom
  • souoiksouoik Member Posts: 128
    But if i have authore configuration code not 1 , and where i can insert this code before item.insert or after
  • Developer101Developer101 Member Posts: 552
    Sorry I didn’t understand your question. Please could you type it more clearly
    United Kingdom
  • souoiksouoik Member Posts: 128
    @Developer101 ok firstly thank you, seconde you can have 1 or 2 template code ok how can set whish one use ok, and am currently to validate lines from my spécifications table whish am importer from excel so i have à validate function for insert into item database rhe Last line is item.insert so where can add your code before insert or after or before
    if mytable.findset then
    Repeat


    Item.insert

    Until mutable.next =0;
  • Developer101Developer101 Member Posts: 552
    Answer ✓
    Not a problem.
    You can have one template code at a time to create an Item. You have to know which one to use. Maybe store this code in your table, for example, in a field ConfigurationTemplateCode

    Then your code will be something like this :

    if mytable.findset then
    repeat

    ConfigurationHeader.RESET;
    ConfigurationHeader.SETRANGE(Code,mytable.ConfigurationTemplateCode);
    ConfigurationHeader.FINDFIRST;
    ItemTemplate.InsertItemFromTemplate(ConfigurationHeader,Item);

    until mytable.next = 0;
    United Kingdom
  • souoiksouoik Member Posts: 128
    @Developer101 in "Item Template"; haven't InsertItemFromTemplate in business central cloud juste one global funtcion CopyFromTemplate , and setrange ConfigurationHeader.SETRANGE(Code,mytable.ConfigurationTemplateCode); i haven't to code template in my table so i need to insert automatically first code
  • Developer101Developer101 Member Posts: 552
    Sorry check Codeunit "Item Templ. Mgt." instead of Item Template.
    United Kingdom
  • souoiksouoik Member Posts: 128
    Yes on this codeunit i see function applytemplateitem so how can be called this function on after item.insert on my code
    Thank you for sharing
  • Developer101Developer101 Member Posts: 552
    can be used in similar way. Have you checked the function CreateItemFromTemplate of this codeunit and its parameters?
    United Kingdom
  • souoiksouoik Member Posts: 128
    I shared whit you thé function onthis code unit ok , and my parte of insert line into item table for create new item
  • Developer101Developer101 Member Posts: 552
    Ok great hopefully all good now
    United Kingdom
  • souoiksouoik Member Posts: 128
    @Developer101 this my code
    // Update or Insert Categorie
    ConfigurationHeader.SetRange("Table ID", 27);
    ConfigurationHeader.SetRange(Code,ItemRecBuffer.ModelItem);
    if ItemTemplat.FindSet() then begin
    ItemTemplMgt.UpdateItemFromTemplate(ItemRec);
    Itempage.EnableControls();
    Itempage.Update();
    end;
    // Update or Insert Categorie
    //first check Parent
    ItemRec.Insert(true);

    ItemTemplMgt:codeunit codeunit 1336 "Item Templ. Mgt."
    i use this function
    UpdateItemFromTemplate

    procedure UpdateItemFromTemplate(var Item: Record Item)
    var
    IsHandled: Boolean;
    begin
    IsHandled := false;
    OnUpdateItemFromTemplate(Item, IsHandled);
    if IsHandled then
    exit;

    UpdateFromTemplate(Item, IsHandled);
    end;

    local procedure UpdateFromTemplate(var Item: Record Item; var IsHandled: Boolean)
    var
    ItemTempl: Record "Item Templ.";
    begin
    IsHandled := false;
    OnBeforeUpdateFromTemplate(Item, IsHandled);
    if IsHandled then
    exit;

    if not CanBeUpdatedFromTemplate(ItemTempl, IsHandled) then
    exit;

    ApplyItemTemplate(Item, ItemTempl, GetUpdateExistingValuesParam());
    end;
    ///
    author function in this codeunit .
    procedure ApplyItemTemplate(var Item: Record Item; ItemTempl: Record "Item Templ."; UpdateExistingValues: Boolean)
    begin
    ApplyTemplate(Item, ItemTempl, UpdateExistingValues);
    InsertDimensions(Item."No.", ItemTempl.Code, Database::Item, Database::"Item Templ.");
    OnApplyItemTemplateOnBeforeItemGet(Item, ItemTempl, UpdateExistingValues);
    Item.Get(Item."No.");
    end;

    plase if you can give the correct syntax ti use this codeunit for applying item template
  • Developer101Developer101 Member Posts: 552
    CreateItemFromTemplate is the function I would use to create an item from a template . I am just helping you to see which function you could use (refer to your original query). The rest you will know better what you are trying to achieve. May be message me on private and we go through it.
    United Kingdom
Sign In or Register to comment.