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
@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
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
@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
@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
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.
Answers
ItemTemplate: Record "Item Template";
Item: Record Item;
ConfigurationHeader: Record "Config. Template Header";
ConfigurationHeader.RESET;
ConfigurationHeader.SETRANGE(Code,'ITEM000001');
ConfigurationHeader.FINDFIRST;
ItemTemplate.InsertItemFromTemplate(ConfigurationHeader,Item);
if mytable.findset then
Repeat
Item.insert
Until mutable.next =0;
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;
Thank you for sharing
// 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